local extension = Package("lvshi_standard")
extension.extensionName = "lvshisha"

Fk:loadTranslationTable{
  ["lvshi_standard"] = "氯师标包",
  ["lvshi"] = "氯师杀",
}

local U = require "packages/utility/utility"
local ls = require 'packages/lvshisha/utility/lvshi_util'
local DIY = require "packages/diy_utility/diy_utility"
local TT = require "packages/tuntian_studio/utility"

local caocao = General(extension, "lvshi__caocao", "wei", 4)
caocao.strategy = "schemecourage"

Fk:addPoxiMethod{
  name = "jianxiong",
  card_filter = function(to_select, selected, data)
    local s = Fk:getCardById(to_select).color
    for _, id in ipairs(selected) do
      if Fk:getCardById(id).color == s then return false end
    end
    return true
  end,
  feasible = function(selected, data)
    return #selected == 2
  end,
  prompt = "奸雄：你可选择中央区内两张颜色不同的牌"
}

local lvshi__jianxiong = fk.CreateTriggerSkill{
  name = "lvshi__jianxiong",
  anim_type = "drawcard",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self.name) then
      local ids = player.room:getBanner("@$CenterArea")
      return #ids > 0 and #player.room.logic:getEventsOfScope(GameEvent.ChangeHp, 1, function (e)
        local damage = e.data[5]
        if damage and (player == damage.from or player == damage.to) then
          return true
        end
      end, Player.HistoryTurn) > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if room:getBanner("@$CenterArea") == nil then return end
    local ids = room:getBanner("@$CenterArea")
    if #ids == 0 then return false end
    --[[local cards = room:askForPoxi(player, "jianxiong", {
      { "centerzone", ids },
    })
    if #cards > 0 then
      room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, self.name)
    end]]
    local id = room:askForCardChosen(target, target, { card_data = {{self.name, ids}} }, self.name)
    room:moveCardTo(id, Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, true)
    if room:getBanner("@$CenterArea") and #room:getBanner("@$CenterArea") > 0 then
      local cards = table.filter(room:getBanner("@$CenterArea"), function (cd) return Fk:getCardById(cd).color ~= Fk:getCardById(id).color end)
      if #cards > 0 then
        id = room:askForCardChosen(player, player, { card_data = {{self.name, cards}} }, self.name)
        room:moveCardTo(id, Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, true)
      end
    end
  end,
}
lvshi__jianxiong.CenterArea = true
caocao:addSkill(lvshi__jianxiong)

local huibian = fk.CreateActiveSkill{
  name = "lvshi__huibian$",
  anim_type = "control",
  prompt = "请选择两名魏势力角色",
  target_num = 2,
  card_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    if #selected < 2 then
      local target = Fk:currentRoom():getPlayerById(to_select)
      return target.kingdom == "wei" and Fk.generals[target.general].truekingdom ~= "ywei"
    else
      return false
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target1 = room:getPlayerById(effect.tos[1])
    local target2 = room:getPlayerById(effect.tos[2])
    room:damage{
      from = player,
      to = target1,
      damage = 1,
      skillName = self.name,
    }
    if not target1.dead then
      local all_choices = {"huibian_draw", "huibian_recover:"..target2.id}
      local choices = table.simpleClone(all_choices)
      if target2.dead or not target2:isWounded() then
        table.removeOne(choices, all_choices[2])
      end
      local choice = room:askForChoice(target1, choices, self.name, nil, false, all_choices)
      if choice == all_choices[1] then
        target1:drawCards(2, self.name)
      else
        room:recover{
          who = target2,
          num = 1,
          recoverBy = player,
          skillName = self.name
        }
      end
    end
  end,
}

caocao:addSkill(huibian)

Fk:loadTranslationTable{
  ["lvshi__caocao"] = "曹操",
  ["#lvshi__caocao"] = "孤行问世",
  ["illustrator:lzsj__huangchao"] = "",
  ["designer:lzsj__huangchao"] = "洛清&太师",
  ["lvshi__jianxiong"] = "奸雄",
  [":lvshi__jianxiong"] = "一名角色的回合结束时，若你于此回合造成或受到过伤害，你可获得中央区内当前回合角色选择的一张牌，然后你获得中央区内一张与之颜色不同的牌。",
  ["lvshi__huibian"] = "挥鞭",
  [":lvshi__huibian"] = "主公技，阶段技，你可选择两名魏势力角色，你对前者造成1点伤害，然后其选择摸两张牌或令后者回复1点体力。",
  ["huibian_draw"] = "摸两张牌",
  ["huibian_recover"] = "令%src回复1点体力",

  ["$lvshi__jianxiong1"] = "大忠似奸，留一世功名，前人赞，今人叹，后人羡！",
  ["$lvshi__jianxiong2"] = "乱世称雄，立一方基业，屯万兵，聚百将，拥千城！",
  ["$lvshi__huibian1"] = "吾任天下之智力，以道御之，无所不可。",
  ["$lvshi__huibian2"] = "青青子衿，悠悠我心，但为君故，沉吟至今。",
  ["~lvshi__caocao"] = "此生已谋大业，难再谋身。",
}

local xunyu = General(extension, "lvshi__xunyu", "wei", 3)
xunyu.strategy = "scheme"
local lvshi__quhu = fk.CreateActiveSkill{
  name = "lvshi__quhu",
  anim_type = "control",
  prompt = "你可以令两名角色拼点",
  max_phase_use_time = 1,
  card_num = 0,
  target_num = 2,
  target_filter = function(self, to_select, selected)
    return #selected < 2 and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    local tos = effect.tos
    local target1 = room:getPlayerById(tos[1])
    local target2 = room:getPlayerById(tos[2])
    local pindianData = target1:pindian({ target2 }, self.name)
    local winner = pindianData.results[target2.id].winner
    if winner then
      local choices = {"lvshi__quhu1:"..winner.id, "lvshi__quhu2"}
      local choice = room:askForChoice(from, choices, self.name)
      local victim = from
      if choice == choices[1] then
        local to = room:askForChoosePlayers(winner, table.map(room.alive_players, Util.IdMapper), 1, 1, "#quhu-choose", self.name, false)
        victim = room:getPlayerById(to[1])
      end
      room:damage{
        from = winner,
        to = victim,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      }
    end
  end
}

local lvshi__jieming = fk.CreateTriggerSkill{
  name = "lvshi__jieming",
  anim_type = "masochism",
  events = {fk.Damaged},
  on_trigger = function(self, event, target, player, data)
    self.cancel_cost = false
    for i = 1, data.damage do
      if self.cancel_cost then break end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function (p) return p:getHandcardNum() ~= 4 end)
    local to = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#jieming-choose", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
    self.cancel_cost = true
  end,
  on_use = function(self, event, target, player, data)
    local to = player.room:getPlayerById(self.cost_data)
    if to:getHandcardNum() < 4 then
      to:drawCards(4 - to:getHandcardNum())
    else
      local n = to:getHandcardNum() - 4
      if n > 0 then
        player.room:askForDiscard(to, n, n, false, self.name, false)
      end
    end
  end,
}

xunyu:addSkill(lvshi__quhu)
xunyu:addSkill(lvshi__jieming)

Fk:loadTranslationTable{
  ["lvshi__xunyu"] = "荀彧",
  ["#lvshi__xunyu"] = "君远香留",
  ["designer:lvshi__xunyu"] = "拉普拉斯",
  ["lvshi__quhu"] = "驱虎",
  [":lvshi__quhu"] = "阶段技，你可令两名角色拼点，然后你选择:1.令赢的角色对一名其选择的角色造成1点伤害；2.令赢的角色对你造成1点伤害。",
  ["#quhu-choose"] = "驱虎：请选择一名角色",
  ["lvshi__quhu1"] = "对%src选择的角色造成1点伤害",
  ["lvshi__quhu2"] = "对你造成1点伤害",
  ["lvshi__jieming"] = "节命",
  [":lvshi__jieming"] = "当你受到1点伤害后，你可令一名角色将手牌调整至四张。",
  ["#jieming-choose"] = "节命：你可令一名角色将手牌调整至四张",

  ["$lvshi__quhu1"] = "厉虎短智，自当为我所用！",
  ["$lvshi__quhu2"] = "损彼以利己，其道上行也。",
  ["$lvshi__jieming1"] = "三尺之躯，亦可死节也！",
  ["$lvshi__jieming2"] = "襄曹而秉汉，守节而立命。",
  ["~lvshi__xunyu"] = "世间安得两全法，不负曹公不负心。",
}

local caoren = General(extension, "lvshi__caoren", "wei", 4)
caoren.strategy = "courage"

local lvshi__lizhan = fk.CreateTriggerSkill{
  name = "lvshi__lizhan",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards(4)
    local result = room:askForYiji(player, cards, room.alive_players, self.name, 0, 4, "#lvshi__lizhan-give", cards, false, 2)
    for p, _ in pairs(result) do
      local to = room:getPlayerById(p)
      if #result[p] > 0 and #to:getCardIds("e") == 0 then
        if not U.askForUseRealCard(room, to, table.filter(to:getCardIds("h"), function (id) return Fk:getCardById(id).type == Card.TypeEquip end),
           ".", self.name, "#lvshi__lizhan-use") then
          player.room:askForDiscard(to, 1, 1, true, self.name, false)
        end
      end
    end
  end,
}

local lvshi__yanzheng = fk.CreateTriggerSkill{
  name = "lvshi__yanzheng",
  anim_type = "support",
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and (player == target or ls.isFriend(player, target)) and target:getMark("lvshi__yanzheng") == 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#lvshi__yanzheng:"..target.id)
  end,  
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(target, "lvshi__yanzheng")
    local eqipSlots = target:getAvailableEquipSlots()
    local n = #target:getCardIds("e") + 1
    room:abortPlayerArea(target, eqipSlots)
    if n > 0 then
      room:recover({
        who = target,
        num = n,
        recoverBy = player,
        skillName = self.name
      }) 
    end
    room:handleAddLoseSkills(target, "lvshi__yanzheng_buff")
  end,
}

local lvshi__yanzheng_buff = fk.CreateViewAsSkill{
  name = "lvshi__yanzheng_buff",
  anim_type = "defensive",
  pattern = "nullification",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeEquip
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("nullification")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
  enabled_at_play = function (self, player)
    return false
  end,
}

local lvshi__yanzheng_maxcards = fk.CreateMaxCardsSkill{
  name = "#llvshi__yanzheng_maxcards",
  exclude_from = function(self, player, card)
    return player:hasSkill(lvshi__yanzheng_buff) and card.type == Card.TypeEquip
  end,
}

caoren:addSkill(lvshi__lizhan)
caoren:addSkill(lvshi__yanzheng)
lvshi__yanzheng_buff:addRelatedSkill(lvshi__yanzheng_maxcards)
Fk:addSkill(lvshi__yanzheng_buff)

Fk:loadTranslationTable{
  ["lvshi__caoren"] = "曹仁",
  ["#lvshi__caoren"] = "天将临城",
  ["designer:lvshi__caoren"] = "氯",
  ["lvshi__lizhan"] = "励战",
  [":lvshi__lizhan"] = "回合结束时，你可观看牌堆顶的四张牌并分配给任意名角色（每名角色至多两张），然后若以此法获得牌的角色的装备区内没有牌，其须使用一张装备牌或弃置一张牌。",
  ["#lvshi__lizhan-give"] = "你可以分配给任意角色，每名角色至多分配两张牌",
  ["#lvshi__lizhan-use"] = "励战：请使用一张装备牌，否则弃置一张牌",

  ["lvshi__yanzheng"] = "严整",
  [":lvshi__yanzheng"] = "当己方角色进入濒死状态时，你可令其废除装备区并回复X点体力（X为以此法弃置的装备牌数+1），然后其本局游戏装备牌不计入手牌上限，且可将装备牌当【无懈可击】使用。",
  ["lvshi__yanzheng_buff"] = "严整",
  ["#lvshi__yanzheng"] = "严整：你可令%src废除装备区并回复体力",
  [":lvshi__yanzheng_buff"] = "你可将一张装备牌当【无懈可击】使用",

  ["$lvshi__lizhan1"] = "良将如匠，雕朽木为栋，化顽石为铁。",
  ["$lvshi__lizhan2"] = "万卒入伍，练之数旬，余之二三者可称锐。",
  ["$lvshi__yanzheng1"] = "千里之行，必积跬步，军风蔚然，必成强军。",
  ["$lvshi__yanzheng2"] = "众军成城，肃风整备，其皆可以一当十。",
  ["~lvshi__caoren"] = "江南未靖，怎可撒手人寰。",
}

local xunyou = General(extension, "lvshi__xunyou", "wei", 3)
xunyou.strategy = "scheme"

local lvshi__qice = fk.CreateViewAsSkill{
  name = "lvshi__qice",
  prompt = "#lvshi__qice",
  pattern = ".|.|.|.|.|trick",
  card_filter = Util.FalseFunc,
  interaction = function()
    local names = {}
    if Fk.currentResponsePattern == "nullification" then
      table.insertIfNeed(names, "lvshi__nullification")
    else
      for _, id in ipairs(Fk:getAllCardIds()) do
        local card = Fk:getCardById(id)
        if card:isCommonTrick() and not card.is_derived then
          local c = Fk:cloneCard(card.name)
          if Fk.currentResponsePattern == nil and card.skill:canUse(Self, c) and not Self:prohibitUse(c) then
            table.insertIfNeed(names, card.name)
          end
        end
      end
    end
    local qicenames = Self:getTableMark("qice_names")
    for _, name in ipairs(qicenames) do
      table.removeOne(names, name)
    end
    if #names == 0 then return false end
    return U.CardNameBox { choices = names }
  end,
  view_as = function(self, cards)
    if #cards ~= 0 or not self.interaction.data then return nil end
    if Fk.currentResponsePattern == "nullification" and string.find(self.interaction.data, "lvshi__nullification") then
      card = Fk:cloneCard(self.interaction.data)
    else
      card = Fk:cloneCard(self.interaction.data)
    end
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    local qicenames = player:getTableMark("qice_names")
    table.insertIfNeed(qicenames, use.card.name)
    player.room:setPlayerMark(player, "qice_names", qicenames)
    if player:getHandcardNum() ~= 1 then
      local n = math.abs(player:getHandcardNum() - 1)
      if player:getHandcardNum() > 1 then
        player.room:askForDiscard(player, n, n, false, self.name, false)
      else
        player:drawCards(n, self.name)
      end
    end
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  enabled_at_response = function(self, player, response)
    if response then return false end
    return player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
}

xunyou:addSkill(lvshi__qice)

local lvshi__zhiyu = fk.CreateTriggerSkill{
  name = "lvshi__zhiyu",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = room:askForChoosePlayers(player, table.map(table.filter(room.alive_players, function(p)
      return not p:isKongcheng() end), Util.IdMapper), 2, 2, "#lvshi__zhiyu-choose", self.name, true)
    if #tos == 2 then
      local target1 = room:getPlayerById(tos[1])
      local target2 = room:getPlayerById(tos[2])
      local pindian = target1:pindian({target2}, self.name)
      local recover = false
      if pindian.results[target2.id].winner then
        local winner
        if pindian.results[target2.id].winner == target1 then
          winner = target1
        else
          winner = target2
        end
        if not winner:isNude() and not winner.dead then
          if room:askForSkillInvoke(winner, self.name, nil, "#lvshi__zhiyu-recover:"..player.id) then
            recover = true
            room:recover({
              who = player,
              num = 1,
              recoverBy = player,
              skillName = self.name
            })
          end
        end
      end
      if not recover then
        local qicenames = player:getTableMark("qice_names")
        if #qicenames > 0 then
          local choice = room:askForChoice(player, qicenames, self.name, "#lvshi__ice_reset")
          table.removeOne(qicenames, choice)
        end
        room:setPlayerMark(player, "qice_names", qicenames)
      end
    end
  end,
}

xunyou:addSkill(lvshi__zhiyu)

Fk:loadTranslationTable{
  ["lvshi__xunyou"] = "荀攸",
  ["#lvshi__xunyou"] = "策佚名传",
  ["designer:lvshi__xunyou"] = "氯",
  ["lvshi__qice"] = "奇策",
  ["#lvshi__qice"] = "奇策：请选择锦囊牌名称和目标角色",
  [":lvshi__qice"] = "回合技，你可将手牌数调整至1，视为使用一张未以此法使用过的通常锦囊牌。",
  ["lvshi__zhiyu"] = "智愚",
  [":lvshi__zhiyu"] = "当你受到伤害后，你可令两名角色拼点，拼点赢的角色可令你回复1点体力，否则你重置“奇策”的一个牌名。",
  ["#lvshi__ice_reset"] = "智愚",
  ["#lvshi__zhiyu-choose"] = "智愚：你可令两名角色拼点",
  ["#lvshi__zhiyu-recover"] = "智愚：你可令%src回复1点体力",
  ["#zhiyu-reset"] = "智愚：你可令%src重置“奇策”",

  ["$lvshi__qice1"] = "腹有经纶，到用时施无穷之计。",
  ["$lvshi__qice2"] = "胸纳甲兵，烽烟起可靖疆晏海。",
  ["$lvshi__zhiyu1"] = "二袁相争，此曹公得利之时。",
  ["$lvshi__zhiyu2"] = "穷寇宜追，需防死蛇之不僵。",
  ["~lvshi__xunyou"] = "吾知命之寿，明知命之节。",
}

local xiahoudun = General(extension, "lvshi__xiahoudun", "wei", 4)
xiahoudun.strategy = "courage"

local zhuomu = fk.CreateTriggerSkill{
  name = "lvshi__zhuomu",
  anim_type = "masochism",
  events = {fk.EventPhaseStart, fk.Damaged, fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.EventPhaseStart then
        return target == player and player.phase == Player.Play
      elseif event == fk.Damaged then
        return target == player
      else
        return #player:getTableMark("@[player]zhuomu-turn") ~= 0
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart or event == fk.Damaged then
      local to = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player), function(p)
        return p.id end), 1, 1, "#lvshi__zhuomu-target", self.name, true)
      if #to > 0 then
        self.cost_data = to[1]
        return true
      end
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart or event == fk.Damaged then
      room:addTableMark(player, "@[player]zhuomu-turn", self.cost_data)
      room:damage({
        from = player,
        to = room:getPlayerById(self.cost_data),
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
    else
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if table.contains(player:getTableMark("@[player]zhuomu-turn"), p.id) then
          local n = player:getLostHp() + 1
          local discards = room:askForDiscard(p, n, n, true, self.name, true, ".", "#lvshi__zhuomu-discard:::"..n)
          if #discards > 0 then
            room:recover{who = p, num = 1, skillName = self.name}
          end
        end
      end
    end
  end,
}

xiahoudun:addSkill(zhuomu)

Fk:loadTranslationTable{
  ["lvshi__xiahoudun"] = "夏侯惇",
  ["#lvshi__xiahoudun"] = "苍心蕴烈",
  ["designer:lvshi__xiahoudun"] = "Jordan圣帝",
  ["lvshi__zhuomu"] = "擢目",
  ["@[player]zhuomu-turn"] = "擢目",
  [":lvshi__zhuomu"] = "出牌阶段开始时或当你受到伤害后，你可对一名其他角色造成1点伤害；此回合结束时，其可弃置X张牌并回复1点体力（X为你已损失的体力值+1）。",
  ["#lvshi__zhuomu-target"] = "擢目：你可对一名其他角色造成1点伤害",
  ["#lvshi__zhuomu-discard"] = "擢目：你可弃置%arg张牌并回复1点体力",

  ["$lvshi__zhuomu1"] = "战斗，存活，然后继续下一场战斗。",
  ["$lvshi__zhuomu2"] = "独眼，是男人的浪漫！",
  ["~lvshi__xiahoudun"] = "后退？那是再次出击的铺垫。",
}

local simayi = General(extension, "lvshi__simayi", "wei", 3)
simayi.strategy = "scheme"

local lvshi__yingshi = fk.CreateTriggerSkill{
  name = "lvshi__yingshi",
  anim_type = "control",
  events = {fk.RoundStart, fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    if event == fk.RoundStart then
      return player:hasSkill(self)
    else
      return player:hasSkill(self) and table.contains(player:getTableMark("yingshi-round"), target.id)
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.RoundStart then
      local n = player.maxHp
      local tos = player.room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, n, "#lvshi__yingshi-choose:::"..n, self.name, true)
      if #tos > 0 then
        self.cost_data = tos
        return true
      end
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.RoundStart then
      player:drawCards(#self.cost_data, self.name)
      room:setPlayerMark(player, "yingshi-round", self.cost_data)
      for _, p in ipairs(self.cost_data) do
        room:addPlayerMark(room:getPlayerById(p), "@@ls__yingshi-round")
      end
    else
      if not player:isNude() then
        local card = room:askForCard(player, 1, 1, true, self.name, false, ".", "#lvshi__yingshi-card")
        room:moveCards({
          ids = card,
          from = player.id,
          toArea = Card.DrawPile,
          moveReason = fk.ReasonJustMove,
          skillName = self.name,
        })
      end
    end
  end,
}

local lvshi__langgu = fk.CreateTriggerSkill{
  name = "lvshi__langgu",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_cost = function(self, event, target, player, data)
    local targets = table.map(table.filter(player.room.alive_players, function (p)
      return player:inMyAttackRange(p) and not p:isNude()
    end), Util.IdMapper)
    local to = player.room:askForChoosePlayers(player, targets, 1, 1, "#lvshi__langgu-choose", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    local card = room:askForCardChosen(player, to, "he", self.name)
    room:obtainCard(player.id, card, false, fk.ReasonPrey)
  end,
}

local langgu__visible = fk.CreateVisibilitySkill{
  name = '#langgu__visible',
  card_visible = function(self, player, card)
    if player:hasSkill(self) and Fk:currentRoom():getCardArea(card) == Card.PlayerHand
    and Fk:currentRoom():getCardOwner(card) and player:inMyAttackRange(Fk:currentRoom():getCardOwner(card)) then
      return true
    end
  end
}

lvshi__langgu:addRelatedSkill(langgu__visible)
simayi:addSkill(lvshi__yingshi)
simayi:addSkill(lvshi__langgu)

Fk:loadTranslationTable{
  ["lvshi__simayi"] = "司马懿",
  ["#lvshi__simayi"] = "洛水无声",
  ["designer:lvshi__simayi"] = "氯",
  ["lvshi__yingshi"] = "鹰视",
  [":lvshi__yingshi"] = "一轮开始时，你可选择至多X名角色并摸等量的牌（X为你的体力上限），此轮这些角色的回合开始时，你须将一张牌置于牌堆顶。",
  ["#lvshi__yingshi-choose"] = "鹰视：你可以选择%arg名角色",
  ["#lvshi__yingshi-card"] = "鹰视：请选择一张牌置于牌堆顶",
  ["@@ls__yingshi-round"] = "鹰视",
  ["lvshi__langgu"] = "狼顾",
  [":lvshi__langgu"] = "你攻击范围内的角色的手牌对你可见；当你受到伤害后，你可获得攻击范围内一名角色的一张牌。",
  ["#lvshi__langgu"] = "狼顾：你可观看%dest的手牌",
  ["#lvshi__langgu-choose"] = "狼顾：你可获得攻击范围内一名角色的一张牌",

  ["$lvshi__yingshi1"] = "烽烟起大荒，戎军远役，问不臣者谁？",
  ["$lvshi__yingshi2"] = "挥斥千军之贲，长驱万里之远。",
  ["$lvshi__langgu1"] = "洛水为誓，皇天为证，吾意不在刀兵。",
  ["$lvshi__langgu2"] = "以谋代战，攻形不以力，攻心不以勇。",
  ["~lvshi__simayi"] = "以权谋而立者，必失大义于千秋。",
}

local xiahouyuan = General(extension, "lvshi__xiahouyuan", "wei", 4)
xiahouyuan.strategy = "courage"

local shensu = fk.CreateTriggerSkill{
  name = "lvshi__shensu",
  anim_type = "offensive",
  events = {fk.EventPhaseStart, fk.Damage},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.EventPhaseStart then
        return player.phase == Player.Judge or player.phase == Player.Draw or player.phase == Player.Play or player.phase == Player.Discard
      else
        return data.card and data.card.skillName == self.name and #data.to:getCardIds("ej") > 0
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    if event == fk.EventPhaseStart then
      local _, dat = player.room:askForUseActiveSkill(player, "#lvshi__shensu_viewas", "#lvshi__shensu-choose", true)
      if dat then
        self.cost_data = {tos = dat.targets, flag = dat.interaction}
        return true
      end
    else
      return player.room:askForSkillInvoke(player, self.name, nil, "#lvshi__shensu-damage:"..data.to.id)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      local flag = "h"
      if self.cost_data.flag == "$Judge" then
        flag = "j"
      elseif self.cost_data.flag == "$Equip" then
        flag = "e"
      end
      room:useVirtualCard("lvs_thunder__slash", player:getCardIds(flag), player, table.map(self.cost_data.tos, Util.Id2PlayerMapper), self.name)
    else
      local card_data = {}
      local from = data.to
      local to = player
      local cards = table.filter(from:getCardIds("e"), function (id)
        return from:canMoveCardInBoardTo(to, id)
      end)
      if #cards > 0 then
        table.insert(card_data, {"$Equip", cards})
      end
      cards = table.filter(from:getCardIds("j"), function (id)
        return from:canMoveCardInBoardTo(to, id)
      end)
      if #cards > 0 then
        table.insert(card_data, {"$Judge", cards})
      end
      --local card = room:askForPoxi(player, self.name, card_data, dat, false)
      local card = room:askForCardChosen(player, data.to, { card_data = card_data }, self.name)
      room:moveCardTo(card, room:getCardArea(card), to, fk.ReasonJustMove, self.name, nil, true, player.id)
    end
  end,
}

local shensu_viewas = fk.CreateViewAsSkill{
  name = "#lvshi__shensu_viewas",
  interaction = function(self, player)
    local all_choices = {"$Judge", "$Hand", "$Equip"}
    local choices = table.simpleClone(all_choices)
    if player:isKongcheng() then table.removeOne(choices, "$Hand") end
    if #player:getCardIds("e") == 0 then table.removeOne(choices, "$Equip") end
    if #player:getCardIds("j") == 0 then table.removeOne(choices, "$Judge") end
    return UI.ComboBox {choices = choices, all_choices = all_choices }
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    if #cards ~= 0 or not self.interaction.data then return end
    local card = Fk:cloneCard("lvs_thunder__slash")
    card.skillName = "lvshi__shensu"
    return card
  end,
}

Fk:addSkill(shensu_viewas)
xiahouyuan:addSkill(shensu)

Fk:loadTranslationTable{
  ["lvshi__xiahouyuan"] = "夏侯渊",
  ["#lvshi__xiahouyuan"] = "飞豹踏魂",
  ["designer:lvshi__xiahouyuan"] = "氯",
  ["lvshi__shensu"] = "神速",
  ["#lvshi__shensu_viewas"] = "神速",
  [":lvshi__shensu"] = "当你的一个<a href='main_phase'>主要阶段</a>开始时，你可将一个区域内的所有牌当雷【杀】使用，此【杀】造成伤害后，你可移动对方场上一张牌至你相同区域。",
  ["#lvshi__shensu-choose"] = "你可以将一个区域内的所有牌当雷【杀】使用",
  ["#lvshi__shensu-damage"] = "神速：你可以移动%src场上一张牌至你相同区域",

  ["$lvshi__shensu1"] = "疾风拂面，日隔千里！",
  ["$lvshi__shensu2"] = "大步流星，不知所由！",
  ["$lvshi__shensu3"] = "奔轶绝尘，不留踪影！",
  ["$lvshi__shensu4"] = "健步如飞，破敌不备！",
  ["~lvshi__xiahouyuan"] = "最恨黄汉升，最憾定军山。",
}

local zhangliao = General(extension, "lvshi__zhangliao", "wei", 4)
zhangliao.strategy = "courage"

local duorui = fk.CreateTriggerSkill{
  name = "lvshi__duorui",
  anim_type = "control",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if player:hasSkill(self) and player:usedSkillTimes(self.name) == 0 and room.current ~= player
    and not room.current:isKongcheng() then
      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile then
          local ids = room:getBanner("@$CenterArea")
          return #ids >= player:getHandcardNum()
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local id = room:askForCardChosen(player, room.current, "h", self.name)
    room:obtainCard(player.id, id, false, fk.ReasonPrey)
  end,
}

duorui.CenterArea = true
zhangliao:addSkill(duorui)
Fk:loadTranslationTable{
  ["lvshi__zhangliao"] = "张辽",
  ["#lvshi__zhangliao"] = "征云裂川",
  ["designer:lvshi__zhangliao"] = "氯",
  ["lvshi__duorui"] = "夺锐",
  [":lvshi__duorui"] = "回合技，当牌于你的回合外进入中央区后，若中央区内的牌数量不小于你的手牌数，则你可获得当前回合角色的一张手牌。",

  ["$lvshi__duorui1"] = "力慑孙仲谋，威震逍遥津。",
  ["$lvshi__duorui2"] = "尔比之东吴十万大军如何？",
  ["$lvshi__zhiti1"] = "吴人惧我，如稚童之惧梦魇！",
  ["$lvshi__zhiti2"] = "张辽来也，还不速速逃命！",
  ["~lvshi__zhangliao"] = "瓦罐不离井边破，将军难免阵前亡。",
}

local chengyu = General(extension, "lvshi__chengyu", "wei", 3)
chengyu.strategy = "scheme"

local ls__shefu = fk.CreateTriggerSkill{
  name = "lvshi__shefu",
  anim_type = "offensive",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player ~= target and not ls.isFriend(player, target)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local ids = room:getBanner("@$CenterArea")
    if not ids or #ids == 0 then return end
    local cards = table.filter(ids, function(id)
      return Fk:getCardById(id).trueName == "jink" or Fk:getCardById(id).trueName == "nullification"
    end)
    if #cards > 0 then
      local n = #cards
      local targets = table.filter(room.alive_players, function (p) return target == p or ls.isFriend(target, p) end)
      local tos, id = room:askForChooseCardAndPlayers(player, table.map(targets, Util.IdMapper), 1, n, ".", "#lvshi__shefu-choose:::"..n, self.name, true)
      if #tos > 0 then
        self.cost_data = {tos, id}
        return true
      end      
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(self.cost_data[2], self.name, player)
    for _, id in ipairs(self.cost_data[1]) do
      if player.dead then return end
      local p = room:getPlayerById(id)
      if not p.dead then
        room:damage{
          from = player,
          to = p,
          damage = 1,
          skillName = self.name,
        }
      end
    end
  end,
}

local ls__benyu = fk.CreateTriggerSkill{
  name = "lvshi__benyu",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and not table.every(player.room.alive_players, function (p) return p:isNude() end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(table.filter(room.alive_players, function(p) return not p:isAllNude() end), Util.IdMapper)
    local to = room:askForChoosePlayers(player, targets, 1, 1,
      "#lvshi__benyu-choose:::"..tostring(2)..":"..tostring(2), self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = 2
    local to = room:getPlayerById(self.cost_data)
    repeat
      local cards = room:askForCardsChosen(player, to, 1, n, "he", self.name)
      if #cards > 0 then
        room:throwCard(cards, self.name, to, player)
        for _, id in ipairs(cards) do
          local card = Fk:getCardById(id)
          if card.trueName == "peach" or card.trueName == "analeptic" then
            player:drawCards(3, self.name)
          end
        end
        room:addPlayerMark(to, "ls__benyu_target", #cards)
        n = n - #cards
        if n <= 0 then break end
      end
      local targets = table.map(table.filter(room.alive_players, function(p)
        return not p:isNude() end), Util.IdMapper)
      if #targets == 0 then break end
      local tos = room:askForChoosePlayers(player, targets, 1, 1,
        "#lvshi__benyu-choose:::"..tostring(2)..":"..tostring(n), self.name, true)
      if #tos > 0 then
        to = room:getPlayerById(tos[1])
      else
        break
      end
    until player.dead
  end,
}

ls__shefu.CenterArea = true
chengyu:addSkill(ls__shefu)
chengyu:addSkill(ls__benyu)

Fk:loadTranslationTable{
  ["lvshi__chengyu"] = "程昱",
  ["#lvshi__chengyu"] = "岱岳捧日",
  ["designer:lvshi__chengyu"] = "氯",
  ["lvshi__shefu"] = "设伏",
  [":lvshi__shefu"] = "其他角色的回合结束时，你可弃置一张牌并对至多X名阵营与其相同的角色各造成1点伤害。（X为中央区内【闪】和【无懈可击】的数量）",
  ["#lvshi__shefu-choose"] = "设伏：你可选择一张牌和至多 %arg 名角色",
  ["lvshi__benyu"] = "贲育",
  [":lvshi__benyu"] = "当你受到伤害后，你可弃置所有角色共计两张牌，你每以此法弃置一张【桃】或【酒】后，你摸三张牌。",
  ["#lvshi__benyu-choose"] = "贲育：你可以依次选择角色，弃置其手牌或装备区内的牌（共计至多%arg张，还剩%arg2张）",

  ["$lvshi__shefu1"] = "出奇设伏，变诈之兵并作。",
  ["$lvshi__shefu2"] = "命将设伏，守株待兔。",
  ["$lvshi__benyu1"] = "过则不可不攻，攻之则必克。",
  ["$lvshi__benyu2"] = "不去眉睫之祸，而慕贵育之死。", 
  ["~lvshi__chengyu"] = "吾命休矣，何以仰报圣恩于万一。",
}

local liubei = General(extension, "lvshi__liubei", "shu", 4)
liubei.strategy = "schemecourage"

local lvshi__julie = fk.CreateViewAsSkill {
  name = "lvshi__julie",
  mute = true,
  prompt = "#lvshi__julie",
  pattern = ".|.|.|.|.|basic",
  interaction = function(self, player)
    local all_choices = U.getAllCardNames("b")
    local choices = table.simpleClone(all_choices)
    choices = U.getViewAsCardNames(player, self.name, choices)
    return U.CardNameBox { choices = choices, all_choices = all_choices, }
  end,
  card_filter = function(self, to_select, selected)
    return Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
  end,
  view_as = function (self, cards)
    if #cards == 0 or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    self.cost_data = cards
    return card
  end,
  before_use = function (self, player, use)
    local room = player.room
    player:showCards(self.cost_data)
    local suits = player:getMark("@lvshi__julie")
    local n = ls.countSuits(self.cost_data)
    room:setPlayerMark(player, "@lvshi__julie", n)
    if n > suits then
      local i = 1
      if use.card.trueName == "jink" then i = 2
      elseif use.card.trueName == "peach" then i = 3
      elseif use.card.trueName == "analeptic" then i = 4
      elseif use.card.trueName == "pear" then i = 5
      elseif use.card.trueName == "poison" then i = 6
      end 
      room:notifySkillInvoked(player, self.name, "support")
      player:broadcastSkillInvoke(self.name, i)
    else
      local num = 0
      local cards = table.simpleClone(self.cost_data)
      local ret = room:askForYiji(player, cards, room:getOtherPlayers(player), self.name, 1, #cards, "#lvshi__julie-give", nil, false, 1)
      local count = 0
      for p, _ in pairs(ret) do
        if #ret[p] > 0 then
          count = count + 1
        end
      end
      if count > 0 then
        player:drawCards(count, self.name)
      end
      return self.name
    end
  end,
  enabled_at_play = function (self, player)
    return player:usedSkillTimes(self.name, Player.HistoryTurn) < 1 and not player:isKongcheng()
  end,
  enabled_at_response = function (self, player, response)
    return player:usedSkillTimes(self.name, Player.HistoryTurn) < 1 and not player:isKongcheng()
  end,
}

local lvshi__qingzhi = fk.CreateTriggerSkill{
  name = "lvshi__qingzhi$",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.moveReason == fk.ReasonGive or move.moveReason == fk.ReasonPrey then
          if move.from and move.from == player.id and move.to and not table.contains(player:getTableMark("qingzhi-turn"), move.to)
          and (player.room:getPlayerById(move.to).kingdom == "shu" or player.room:getPlayerById(move.to).kingdom == "han") then
            for _, info in ipairs(move.moveInfo) do
              if info.fromArea == Card.PlayerHand then
                return true
              end
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local mark = player:getTableMark("qingzhi-turn")
    for _, move in ipairs(data) do
      if move.moveReason == fk.ReasonGive or move.moveReason == fk.ReasonPrey then
        if move.from and move.from == player.id and move.to and (player.room:getPlayerById(move.to).kingdom == "shu"
        or player.room:getPlayerById(move.to).kingdom == "han") then
          table.insertIfNeed(mark, move.to)
        end
      end
    end
    player.room:setPlayerMark(player, "qingzhi-turn", mark)
    player:drawCards(1, self.name)
  end,
}

local qingzhi_targetmod = fk.CreateTargetModSkill{
  name = "#lvshi__qingzhi_targetmod",
  bypass_distances =  function(self, player, skill, card, to)
    return player:hasSkill(self) and skill.trueName == "slash_skill" and card.skillName == "lvshi__julie"
  end,
  residue_func = function(self, player, skill, scope, card)
    if player:hasSkill(self) and skill.trueName == "slash_skill" and card.skillName == "lvshi__julie" then
      local n = #table.filter(Fk:currentRoom().players, function (p)
        return (p.kingdom == "shu" or p.kingdom == "han") and p.dead end)
      return n
    end
  end,
  extra_target_func = function(self, player, skill, card)
    if player:hasSkill(self) and skill.trueName == "slash_skill" and card.skillName == "lvshi__julie" then
      local n = #table.filter(Fk:currentRoom().players, function (p)
        return (p.kingdom == "shu" or p.kingdom == "han") and p.dead end)
      return n
    end
  end,
}

lvshi__qingzhi:addRelatedSkill(qingzhi_targetmod)
liubei:addSkill(lvshi__julie)
liubei:addSkill(lvshi__qingzhi)

Fk:loadTranslationTable{
  ["lvshi__liubei"] = "刘备",
  ["#lvshi__liubei"] = "渊志无息",
  ["designer:lvshi__liubei"] = "拉普拉斯&氯",
  ["lvshi__julie"] = "聚烈",
  ["@lvshi__julie"] = "聚烈",
  [":lvshi__julie"] = "回合技，当你需要使用或打出一张基本牌时，你可展示任意张手牌，若花色数量多于上次展示，你视为使用或打出之，否则你可分配这些牌给任意名角色各一张，然后你摸等量牌。",
  ["#lvshi__julie"] = "你可展示任意张手牌，视为使用一张基本牌",
  ["#lvshi__julie-give"] = "你可以交给%src一张手牌",
  ["#lvshi__julie-get"] = "你可以获得%src展示的一张牌",
  ["#lvshi__julie-give"] = "你可以分配这些牌",
  ["lvshi__qingzhi"] = "倾志",
  [":lvshi__qingzhi"] = "主公技，锁定技，蜀或汉势力角色于一回合首次获得你的手牌后，你摸一张牌；你因“聚烈”使用【杀】无距离限制，且次数和目标个数上限增加死亡的蜀或汉势力角色数。",

  ["$lvshi__julie1"] = "(视为杀)请君振炎汉之武运，除篡国之逆贼。",
  ["$lvshi__julie2"] = "(视为闪)杀出重围，成王者霸业！",
  ["$lvshi__julie3"] = "(视为桃)仁德之君，则所向披靡也！",
  ["$lvshi__julie4"] = "(视为酒)我将丹心酿烈酒，且取一觞慰风尘。",
  ["$lvshi__julie5"] = "(视为梨)仁施天下，德济众生。",
  ["$lvshi__julie6"] = "(视为毒)卿乃治国之股肱，国贼当前，可欲诛之？",
  ["~lvshi__liubei"] = "大汉之一统，朕。。不复见矣。",
}

local zhugeliang = General(extension, "lvshi__zhugeliang", "shu", 3)
zhugeliang.strategy = "scheme"

local zhizhe = fk.CreateTriggerSkill{
  name = "lvshi__zhizhe",
  anim_type = "control",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:askForGuanxing(player, room:getNCards(7), {0, #room.alive_players})
  end,
}

local jincui = fk.CreateViewAsSkill {
  name = "lvshi__jincui",
  pattern = "jink,nullification",
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    if #cards ~= 0 then return nil end
    local card = Fk:cloneCard("lvshi__jink")
    if Fk.currentResponsePattern == "nullification" then
      card = Fk:cloneCard("lvshi__nullification")
    end
    card.skillName = self.name
    return card
  end,
  enabled_at_play = Util.FalseFunc,
  enabled_at_response = function(self, player, response)
    if response then return false end
    return player:usedSkillTimes(self.name) == 0
  end,
  before_use = function(self, player, use)
    local room = player.room
    local ids = room:getNCards(1, "bottom")
    use.card:addSubcards(ids)
  end,
  after_use = function(self, player, use) 
    if use.card.type ~= Fk:getCardById(use.card.subcards[1]).type then
      player.room:obtainCard(player.id, use.card, true, fk.ReasonJustMove)
      player.room:loseHp(player, 1, self.name)
    end
  end,
}

zhugeliang:addSkill(zhizhe)
zhugeliang:addSkill(jincui)

Fk:loadTranslationTable{
  ["lvshi__zhugeliang"] = "诸葛亮",
  ["#lvshi__zhugeliang"] = "天魄未穷",
  ["designer:lvshi__zhugeliang"] = "氯",
  ["lvshi__zhizhe"] = "智哲",
  [":lvshi__zhizhe"] = "回合开始时，你可<a href=':lvshi__busuan'>卜算</a>7，且你至多将其中X张牌置于牌堆顶。（X为存活角色数）",
  [":lvshi__busuan"] = "<b><font color=\"#D2042D\">观星小技巧：牌堆底最右边为牌堆底第一张，牌堆顶反之</b>",
  ["lvshi__jincui"] = "尽瘁",
  [":lvshi__jincui"] = "回合技，你可将牌堆底的一张牌当【闪】或【无懈可击】使用，若与之类别不同，你失去1点体力并获得此牌。",

  ["$lvshi__zhizhe1"] = "此身抱薪，可付丹鼎，五十四年春秋昭炎汉长明。",
  ["$lvshi__zhizhe2"] = "南征北伐，誓还旧都，二十四代王业不偏安一隅。",
  ["$lvshi__jincui1"] = "战群儒，守空城，今摆乱石八阵，笑谈将军死生。", 
  ["$lvshi__jincui2"] = "汝等多虑，正中下怀。", 
  ["~lvshi__zhugeliang"] = "悠悠苍天，何薄于我。",
}


local guanyu = General(extension, "lvshi__guanyu", "shu", 5)
guanyu.strategy = "courage"
local lvshi__lingwei = fk.CreateViewAsSkill{
  name = "lvshi__lingwei",
  pattern = "slash,drowning",
  interaction = function(self)
    local all_names = {"slash", "drowning"}
    local invoke_names = table.filter(U.getAllCardNames("bt"), function (name)
      return table.contains(all_names, Fk:cloneCard(name).trueName)
    end)
    return U.CardNameBox {choices = invoke_names}
  end,
  card_filter = function(self, to_select, selected, player)
    if not self.interaction.data then return end
    if string.find(self.interaction.data, "drowning") then
      return Fk:getCardById(to_select).trueName == "slash"
    elseif string.find(self.interaction.data, "slash") then
      return Fk:getCardById(to_select).color == Card.Red
    end
  end,
  view_as = function(self, cards)
    if #cards ~= 1 or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(cards)
    card.skillName = self.name
    return card
  end,
}


local lvshi__hezhen = fk.CreateTriggerSkill{
  name = "lvshi__hezhen",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self.name) and data.to == Player.Discard then
      local events = player.room.logic:getEventsOfScope(GameEvent.ChangeHp, 1, function (e)
        local damage = e.data[5]
        if damage and player == damage.from then
          return true
        end
      end, Player.HistoryTurn)
      if #events > 0 then
        --self.cost_data = #events
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1)
    data.to = Player.Play
  end,
}

guanyu:addSkill(lvshi__lingwei)
guanyu:addSkill(lvshi__hezhen)

Fk:loadTranslationTable{
  ["lvshi__guanyu"] = "关羽",
  ["#lvshi__guanyu"] = "义道证武",
  ["designer:lvshi__zhangfei"] = "氯",
  ["lvshi__lingwei"] = "凌威",
  [":lvshi__lingwei"] = "你可将红色牌当任意【杀】使用或打出，你可将【杀】当【水淹七军】使用。",
  ["lvshi__hezhen"] = "赫震",
  [":lvshi__hezhen"] = "锁定技，弃牌阶段开始前，若你于此回合造成过伤害，你摸一张牌并将此阶段改为出牌阶段。",

  ["$lvshi__lingwei1"] = "来将通名，关某刀下不斩无名之鬼！",
  ["$lvshi__lingwei2"] = "卖首之贼，关某面前岂容你放肆！",
  ["$lvshi__hezhen1"] = "胸有怒涛如烈火，偃月刀出，天地失色！",
  ["$lvshi__hezhen2"] = "天下碌碌之辈，安敢小觑关某！",
  ["~lvshi__guanyu"] = "忠节一世，死战不降。",
}

local zhangfei = General(extension, "lvshi__zhangfei", "shu", 4)
zhangfei.strategy = "courage"

local lvshi__shencai = fk.CreateViewAsSkill{
  name = "lvshi__shencai",
  anim_type = "offensive",
  pattern = "slash",
  prompt = "你可以选择中央区内的一张【杀】和目标角色",
  expand_pile = function (self, player)
    return player:getTableMark("lvshi__shencai")
  end,
  card_filter = function (self, to_select, selected)
    local mark = Self:getTableMark("lvshi__shencai")
    return table.contains(mark, to_select) and #selected == 0
  end,
  view_as = function (self, cards)
    if #cards == 1 then
      local card = Fk:cloneCard(Fk:getCardById(cards[1]).name)
      card.skillName = self.name
      card:setMark("shencai-turn", cards[1])
      return card
    end
  end,
  before_use = function(self, player, use)
    local id = use.card:getMark("shencai-turn")
    DIY.RemoveCenterCards(player, id)
  end,
  enabled_at_play = function (self, player)
    return #player:getTableMark("lvshi__shencai") > 0
  end,
  enabled_at_response = Util.FalseFunc,
}

local shencai_record = fk.CreateTriggerSkill{
  name = "#lvshi__shencai_record",
  mute = true,
  events = {fk.TargetSpecified, fk.PreCardEffect},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and data.card.trueName == "slash" and data.card.skillName == "lvshi__shencai" then
      if event == fk.TargetSpecified then
        return target == player
      else
        return true
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      data.disresponsiveList = data.disresponsiveList or {}
      table.insert(data.disresponsiveList, data.to)
    else
      if room:getBanner("@$CenterArea") then
        local to = room:getPlayerById(data.to)
        local jinks = table.filter(room:getBanner("@$CenterArea"), function (id) return Fk:getCardById(id).trueName == "jink" end)
        if #jinks > 0 then
          local id = room:askForCardChosen(to, to, { card_data = {{"lvshi__shencai", jinks}} }, "lvshi__shencai")
          if id then
            DIY.RemoveCenterCards(target, id)
            return true
          end
        end
      end
    end
  end,

  refresh_events = {fk.EventPhaseStart, fk.AfterCardsMove, "fk.AfterCenterAreaRemove"},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and player.phase == Player.Play
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local cards = table.filter(room.discard_pile, function (id)
      return Fk:getCardById(id):getMark(MarkEnum.IncludeCenterCards) > 0 or
        table.find(MarkEnum.TempMarkSuffix, function (suffix)
          return Fk:getCardById(id):getMark(MarkEnum.IncludeCenterCards..suffix) > 0
        end)
    end)
    room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            table.insertIfNeed(cards, info.cardId)
          end
        end
      end
    end, Player.HistoryTurn)
    cards = table.filter(cards, function (id)
      local card = Fk:getCardById(id)
      return table.contains(room.discard_pile, id) and
        table.every(MarkEnum.TempMarkSuffix, function (suffix)
          return card:getMark(MarkEnum.RemoveCenterCards..suffix) == 0
        end)
    end)
    local slashs = table.filter(cards, function (id) return Fk:getCardById(id).trueName == "slash" end)
    room:setPlayerMark(player, "lvshi__shencai", slashs)
  end,
}

local shencai_targetmod = fk.CreateTargetModSkill{
  name = "#lvshi__shencai_targetmod",
  residue_func = function(self, player, skill, scope, card)
    if player:hasSkill(self) and skill.trueName == "slash_skill" and card.skillName == "lvshi__shencai" then
      return 999
    end
  end,
}

local lvshi__xunshi = fk.CreateTriggerSkill{
  name = "lvshi__xunshi",
  mute = true,
  events = {fk.HpChanged, fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self.name) and target == player and player:usedSkillTimes(self.name) == 0 then
      return event == fk.HpChanged or (event == fk.CardUseFinished and data.card.type == Card.TypeTrick)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.HpChanged then
      room:notifySkillInvoked(player, self.name, "masochism")
      player:broadcastSkillInvoke(self.name, table.random({1,2}))
    else
      room:notifySkillInvoked(player, self.name, "drawcard")
      player:broadcastSkillInvoke(self.name, table.random({3,4}))
    end
    local ids = room:getBanner("@$CenterArea")
    if #ids == 0 then player:drawCards(1, self.name) return false end
    local piles = U.askForExchange(player, "$Hand", "centerarea", player:getCardIds{Player.Hand}, ids, "#lvshi__xunshi-invoke", 3)
    if #piles == 0 then player:drawCards(1, self.name) return false end
    local cards1, cards2 = {}, {}
    for _, id in ipairs(piles) do
      if room:getCardArea(id) == Card.PlayerHand then
        table.insert(cards1, id)
      end
    end
    for _, id in ipairs(piles) do
      if room:getCardArea(id) == Card.DiscardPile then
        table.insert(cards2, id)
      end
    end
    local move1 = {
      ids = cards1,
      from = player.id,
      fromArea = Card.PlayerHand,
      toArea = Card.DiscardPile,
      moveReason = fk.ReasonPutIntoDiscardPile,
      skillName = self.name,
    }
    local move2 = {
      ids = cards2,
      to = player.id,
      toArea = Card.PlayerHand,
      moveReason = fk.ReasonJustMove,
      skillName = self.name,
    }
    room:moveCards(move1, move2)
  end,
}

lvshi__shencai.CenterArea = true
lvshi__xunshi.CenterArea = true
lvshi__shencai:addRelatedSkill(shencai_record)
lvshi__shencai:addRelatedSkill(shencai_targetmod)
zhangfei:addSkill(lvshi__shencai)
zhangfei:addSkill(lvshi__xunshi)

Fk:loadTranslationTable{
  ["centerarea"] = "中央区",
  ["lvshi__zhangfei"] = "张飞",
  ["#lvshi__zhangfei"] = "万军夺气",
  ["designer:lvshi__zhangfei"] = "氯",
  ["lvshi__shencai"] = "神裁",
  [":lvshi__shencai"] = "出牌阶段，你可移去中央区的一张【杀】视为无次数限制使用之，目标角色抵消此【闪】的方式改为移去中央区的一张【闪】。",
  ["lvshi__xunshi"] = "巡使",
  [":lvshi__xunshi"] = "回合技，当你的体力值变化后或使用锦囊牌后，你可用一至三张手牌交换中央区内等量的牌，或摸一张牌。",
  ["#lvshi__xunshi-invoke"] = "巡使：你可用一至三张手牌交换中央区内等量的牌，或不选牌直接摸一张牌",
  ["#lvshi__xunshi-cards"] = "巡使：你可以选择至多 %arg 张手牌交换中央区内等量的牌，或点击取消摸一张牌",

  ["$lvshi__shencai1"] = "汝罪之大，似彻天之山、盈渊之海!",
  ["$lvshi__shencai2"] = "生犯贪嗔痴戾疑，死受鞭笞斧灼烹！",
  ["$lvshi__xunshi1"] = "此间不明我明之，此事不平我平之！",
  ["$lvshi__xunshi2"] = "长车琳、铁甲铮，桓侯既至百冤明！",
  ["$lvshi__xunshi3"] = "鸣鼓净街魑魅退，擂瓮升堂罪何人!",
  ["$lvshi__xunshi4"] = "巡界奔走双甲子，归来两界又一秋！",
  ["~lvshi__zhangfei"] = "愿舍神冕入轮回，与吾兄再结金兰。",
}

local zhaoyun = General(extension, "lvshi__zhaoyun", "shu", 4)
zhaoyun.strategy = "courage"

local juejing = fk.CreateTriggerSkill{
  name = "lvshi__juejing",
  frequency = Skill.Compulsory,
  events = {fk.HpChanged},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player-- and data.num < 0
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player:drawCards(1, self.name)
    if player.maxHp > 1 then
      room:changeMaxHp(player, -1)
      room:addPlayerMark(player, "AddMaxCards", 2)
    end
  end,
}

local longhun = fk.CreateViewAsSkill{
  name = "lvshi__longhun",
  mute = true,
  pattern = "peach,slash,jink,nullification",
  card_filter = function(self, to_select, selected, player)
    if #selected == 2 then
      return false
    elseif #selected == 1 then
      return Fk:getCardById(to_select):compareSuitWith(Fk:getCardById(selected[1]))
    else
      local suit = Fk:getCardById(to_select).suit
      local c
      if suit == Card.Heart then
        c = Fk:cloneCard("peach")
      elseif suit == Card.Diamond then
        c = Fk:cloneCard("fire__slash")
      elseif suit == Card.Club then
        c = Fk:cloneCard("jink")
      elseif suit == Card.Spade then
        c = Fk:cloneCard("nullification")
      else
        return false
      end
      return (Fk.currentResponsePattern == nil and c.skill:canUse(player, c)) or (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(c))
    end
  end,
  view_as = function(self, cards)
    if #cards == 0 or #cards > 2 then
      return nil
    end
    local suit = Fk:getCardById(cards[1]).suit
    local c
    if suit == Card.Heart then
      c = Fk:cloneCard("peach")
    elseif suit == Card.Diamond then
      c = Fk:cloneCard("lvs_fire__slash")
    elseif suit == Card.Club then
      c = Fk:cloneCard("jink")
    elseif suit == Card.Spade then
      c = Fk:cloneCard("nullification")
    else
      return nil
    end
    c.skillName = self.name
    c:addSubcards(cards)
    return c
  end,
  before_use = function(self, player, use)
    if #use.card.subcards == 2 and Fk:getCardById(use.card.subcards[1]).color == Card.Red then
      use.additionalDamage = (use.additionalDamage or 0) + 1
      use.additionalRecover = (use.additionalRecover or 0) + 1
    end
  end,
}

local longhun_discard = fk.CreateTriggerSkill{
  name = "#lvshi__longhun_discard",
  events = {fk.CardUseFinished, fk.CardRespondFinished},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and table.contains(data.card.skillNames, "lvshi__longhun") and #data.card.subcards == 2 and Fk:getCardById(data.card.subcards[1]).color == Card.Black
  end,
  on_cost = function() return true end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if not room.current:isNude() then
      local cid = room:askForCardChosen(player, room.current, "he", longhun.name)
      room:throwCard({cid}, longhun.name, room.current, player)
    end
  end,

  refresh_events = {fk.AfterCardUseDeclared, fk.PreCardRespond},
  can_refresh = function(self, event, target, player, data)
    return target == player and table.contains(data.card.skillNames, "lvshi__longhun")
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if data.card.trueName == "nullification" then
      player:broadcastSkillInvoke("lvshi__longhun", 1)
      room:notifySkillInvoked(player, "lvshi__longhun", "control")
    elseif data.card.trueName == "jink" then
      player:broadcastSkillInvoke("lvshi__longhun", 2)
      room:notifySkillInvoked(player, "lvshi__longhun", "defensive")
    elseif data.card.trueName == "peach" then
      player:broadcastSkillInvoke("lvshi__longhun", 3)
      room:notifySkillInvoked(player, "lvshi__longhun", "support")
    elseif data.card.trueName == "slash" then
      player:broadcastSkillInvoke("lvshi__longhun", 4)
      room:notifySkillInvoked(player, "lvshi__longhun", "offensive")
    end
  end,
}
longhun:addRelatedSkill(longhun_discard)
zhaoyun:addSkill(juejing)
zhaoyun:addSkill(longhun)

Fk:loadTranslationTable{
  ["lvshi__zhaoyun"] = "赵云",
  ["#lvshi__zhaoyun"] = "履险终平",
  ["designer:lvshi__zhaoyun"] = "氯",
  ["lvshi__juejing"] = "绝境",
  [":lvshi__juejing"] = "锁定技，当你的体力值变化后，你摸一张牌，然后若你的体力上限大于1，你减1点体力上限，令手牌上限+2。",
  ["lvshi__longhun"] = "龙魂",
  [":lvshi__longhun"] = "你可将至多两张你的同花色的牌按以下规则使用或打出：<font color='red'>♥</font>当【桃】，"..
  "<font color='red'>♦</font>当火【杀】，♣当【闪】，♠当【无懈可击】。若你以此法使用或打出了两张：红色牌，此牌回复和伤害基数+1；黑色牌，你弃置当前回合角色一张牌。",
  ["#lvshi__longhun_discard"] = "龙魂",
  ["$lvshi__juejing1"] = "龙战于野，其血玄黄。",
  ["$lvshi__longhun1"] = "金甲映日，驱邪祛秽。", --无懈
  ["$lvshi__longhun2"] = "腾龙行云，首尾不见。", --闪
  ["$lvshi__longhun3"] = "潜龙于渊，涉灵愈伤。", --桃
  ["$lvshi__longhun4"] = "千里一怒，红莲灿世。", --火杀
  ["~lvshi__zhaoyun"] = "血染鳞甲，龙坠九天。",
}

local fazheng = General(extension, "lvshi__fazheng", "shu", 3)
fazheng.strategy = "scheme"

local aoran = fk.CreateTriggerSkill{
  name = "lvshi__aoran",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) or player:getMark("@@lvshi__aoran1-turn") > 0 or player:getMark("@@lvshi__aoran2-turn") > 0 then return end
    for _, move in ipairs(data) do
      if move.from == player.id or (move.to == player.id and move.toArea == Card.PlayerHand) then
        for _, info in ipairs(move.moveInfo) do
          if move.from == player.id then
            return info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip
          elseif move.to == player.id then
            return true
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askForChoice(player, {"lvshi__aoran1", "lvshi__aoran2"}, self.name)
    room:addPlayerMark(player, "@@"..choice.."-turn")
  end,

  refresh_events = {fk.DamageCaused, fk.DamageInflicted},--反正没有OL骆统，写refresh了
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and (player:getMark("@@lvshi__aoran1-turn") > 0 or player:getMark("@@lvshi__aoran2-turn") > 0)
  end,
  on_refresh = function(self, event, target, player, data) 
    if player:getMark("@@lvshi__aoran1-turn") > 0 then
      player.room:setPlayerMark(player, "@@lvshi__aoran1-turn", 0)
      data.damage = 2
    elseif player:getMark("@@lvshi__aoran2-turn") > 0 then
      player.room:setPlayerMark(player, "@@lvshi__aoran2-turn", 0)
      data.damage = 0
    end
  end,
}

local xuanhuo = fk.CreateViewAsSkill{
  name = "lvshi__xuanhuo",
  pattern = "rockfall,secret_advance",
  interaction = function(self)
    local names = {"lvshi__rockfall", "lvshi__secret_advance"}
    return U.CardNameBox {choices = names}
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    if #cards ~= 0 or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    return card
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end
}

local xuanhuo_trigger = fk.CreateTriggerSkill{
  name = "#ls__xuanhuo_trigger",
  mute = true,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target ~= player and ls.isFriend(player, target) and target.phase == Player.Play 
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForCard(target, 1, 1, true, self.name, true, ".|.|heart", "#lvshi__xuanhuo-give::"..player.id)
    if #card > 0 then
      self.cost_data = card[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:moveCardTo(self.cost_data, Card.PlayerHand, player, fk.ReasonPrey, self.name, "", true, target.id)
    room:handleAddLoseSkills(target, "lvshi__xuanhuo")
    room.logic:getCurrentEvent():findParent(GameEvent.Phase, true, Player.HistoryGame):addCleaner(function ()
      room:handleAddLoseSkills(target, "-lvshi__xuanhuo")
    end)
  end,
}

xuanhuo:addRelatedSkill(xuanhuo_trigger)
fazheng:addSkill(aoran)
fazheng:addSkill(xuanhuo)

Fk:loadTranslationTable{
  ["lvshi__fazheng"] = "法正",
  ["#lvshi__fazheng"] = "言锋谋刃",
  ["designer:lvshi__fazheng"] = "氯",
  ["lvshi__aoran"] = "翱然",
  [":lvshi__aoran"] = "当你获得或失去一次牌后，你可令此回合造成的下一次伤害值为2或0，期间你不能再发动此技能。",
  ["lvshi__aoran1"] = "下一次伤害为2",
  ["lvshi__aoran2"] = "下一次伤害为0",
  ["@@lvshi__aoran1-turn"] = "翱然 伤害2",
  ["@@lvshi__aoran2-turn"] = "翱然 伤害0",
  ["lvshi__xuanhuo"] = "眩惑",
  [":lvshi__xuanhuo"] = "阶段技，你可视为使用【落井下石】或【暗度陈仓】。己方角色的出牌阶段开始时，其可交给你一张红桃牌，获得“眩惑”直到此阶段结束。",    
  ["#lvshi__xuanhuo-prompt"] = "眩惑：你可视为使用【落井下石】或【暗度陈仓】",
  ["#lvshi__xuanhuo_trigger"] = "眩惑",
  ["#lvshi__xuanhuo-give"] = "眩惑：你可以交给 %dest 一张红桃牌",

  ["$lvshi__aoran1"] = "读兵书千卷，今到用时，可左右施为。",
  ["$lvshi__aoran2"] = "我观夏侯渊中调虎离山之计，可击矣。",
  ["$lvshi__xuanhuo1"] = "待其倦怠，我举红旗，将军可虎奔而攻。",
  ["$lvshi__xuanhuo2"] = "夏侯兵至，我举白旗，将军便按兵不动。",

  ["~lvshi__fazheng"] = "蜀翼双折，吾主王业，就靠孔明了…",
}

local pangtong = General(extension, "lvshi__pangtong", "shu", 3)
pangtong.strategy = "scheme"


local sance = fk.CreateTriggerSkill{
  name = "lvshi__sance",
  anim_type = "support",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self.name) and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 then
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Card.PlayerHand then
          return true
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local mark = {}
    for _, move in ipairs(data) do
      if move.to == player.id and move.toArea == Card.PlayerHand then
        for _, info in ipairs(move.moveInfo) do
          table.insertIfNeed(mark, info.cardId)
        end
      end
    end
    room:setPlayerMark(player, "sance-phase", mark)
    return player.room:askForUseActiveSkill(player, "sance_active", "#sance-invoke", true)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards(3)
    room:moveCardTo(cards, Card.Processing, nil, fk.ReasonJustMove, self.name)
    local basics = table.filter(cards, function(id) return Fk:getCardById(id).type == Card.TypeBasic end)
    local tricks = table.filter(cards, function(id) return Fk:getCardById(id).type == Card.TypeTrick end)
    local equips = table.filter(cards, function(id) return Fk:getCardById(id).type == Card.TypeEquip end)
    if #basics > 0 then
      for _, id in ipairs(basics) do
        table.removeOne(cards, id)
      end
      room:moveCardTo(basics, Card.PlayerHand, player, fk.ReasonJustMove, self.name)
    end
    if #tricks > 0 then
      for _, id in ipairs(tricks) do
        table.removeOne(cards, id)
      end
      local targets = table.filter(room.alive_players, function(p) return player == p or ls.isFriend(player, p) end)
      local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#sance-choose", self.name, false)
      if #tos > 0 then
        local target = room:getPlayerById(tos[1])
        room:moveCardTo(tricks, Card.PlayerHand, target, fk.ReasonJustMove, self.name)
        DIY.ShowCards(target, tricks)
      end
    end
    local to_put = table.simpleClone(equips)
    while #to_put > 0 do
      for _, e in ipairs(equips) do       
        local card = Fk:getCardById(e)
        local tos = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, "#sance-put:::"..card:toLogString(), self.name, true)
        if #tos > 0 then
          U.moveCardIntoEquip(room, room:getPlayerById(tos[1]), e, self.name)
          table.removeOne(to_put, e)
          table.removeOne(cards, e)
        else
          break
        end
      end
    end
    if #cards > 0 then
      room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name)
    end
  end,
}

local sance_active = fk.CreateActiveSkill{
  name = "sance_active",
  mute = true,
  card_num = 1,
  target_num = 0,
  card_filter = function(self, to_select, selected, targets)
    return Self:getMark("sance-phase") ~= 0 and table.contains(Self:getMark("sance-phase"), to_select)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:throwCard(effect.cards, self.name, player, player)
  end,
}

local zuixiang = fk.CreateTriggerSkill{
  name = "lvshi__zuixiang",
  anim_type = "defensive",
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.card.color == Card.Black and data.from ~= player.id
  end,
  on_cost = function(self, event, target, player, data)
    if player.drank == 0 then
      return player.room:askForSkillInvoke(player, self.name, nil, "#zuixiang-invoke")
    else
      local shown = DIY.GetShownCards(player)
      --local card = player.room:askForCard(player, 1, 1, true, self.name, true, ".|.|.|supportzone&|.|.", "#zuixiang-card:::"..data.card:toLogString(), "supportzone&")
      local cards = player.room:askForCard(player, 1, 1, false, self.name, true, tostring(Exppattern{ id = shown }), "#zuixiang-card:::"..data.card:toLogString())
      if #cards > 0 then
        self.cost_data = cards
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player.drank == 0 then
      local id = player:drawCards(1)
      DIY.ShowCards(player, id)
      room:useVirtualCard("analeptic", nil, player, player, self.name, false)
    else
      room:throwCard(self.cost_data, self.name, player, player)
      if data.card.sub_type == Card.SubtypeDelayedTrick then
        AimGroup:cancelTarget(data, player.id)
      else
        table.insertIfNeed(data.nullifiedTargets, player.id)
      end
    end
  end,

  refresh_events = {fk.EventPhaseStart, fk.TurnStart, fk.BeforeTurnStart},
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(self.name) then
      if event == fk.EventPhaseStart then
        return target.phase == Player.NotActive and player.drank > 0
      elseif event == fk.TurnStart then
        return target == player and player.drank > 0
      else 
        return player:getMark(self.name) > 0
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      room:setPlayerMark(player, self.name, player.drank)
    elseif event == fk.TurnStart then
      player.drank = 0
      room:broadcastProperty(player, "drank")
    else
      player.drank = player:getMark(self.name)
      room:setPlayerMark(player, self.name, 0)
      if target ~= player then
        room:broadcastProperty(player, "drank")
      end
    end
  end,
}

pangtong:addSkill(sance)
Fk:addSkill(sance_active)
pangtong:addSkill(zuixiang)

Fk:loadTranslationTable{
  ["lvshi__pangtong"] = "庞统",
  ["#lvshi__pangtong"] = "傲凤翔天",
  ["lvshi__sance"] = "三策",
  [":lvshi__sance"] = "回合技，当你获得牌后，你可弃置其中一张牌，亮出牌堆顶三张牌，你获得其中的基本牌，<a href=':@lvshi__zhiyuan'>支援</a>一名角色其中的锦囊牌，将其中的装备牌依次置于一名角色的装备区。",
  ["sance_active"] = "三策",
  ["#sance-invoke"] = "三策：你可以弃置其中一张牌",
  ["#sance-choose"] = "三策：你可以将亮出的锦囊牌支援一名角色",
  ["#sance-put"] = "三策：你可将%arg置于一名角色的装备区",
  ["lvshi__zuixiang"] = "醉乡",
  [":lvshi__zuixiang"] = "你的【酒】效果改为回合开始时消失。当你成为其他角色使用黑色牌的目标后，若你未处于【酒】状态，你可摸一张牌并明置，视为使用【酒】，"..
  "否则你可弃置一张明置牌，令此牌对你无效。",
  ["#zuixiang-invoke"] = "醉乡：你可以支援自己牌堆顶牌，视为使用【酒】",
  ["#zuixiang-card"] = "醉乡：你可以弃置支援区内的一张牌，令%arg对你无效",

  ["$lvshi__sance1"] = "将多兵众，不可以敌。使其自累，以杀其势。",
  ["$lvshi__sance2"] = "善用兵者，运巧必防损，立谋虑中变。",
  ["$lvshi__sance3"] = "用计者，非一计之可孤行，必有数计以相之也。",
  ["$lvshi__sance4"] = "一计累敌，一计攻敌。",
  ["$lvshi__zuixiang1"] = "歌一曲，酒一觞，邀君醉琼浆，东风盈暖房。",
  ["$lvshi__zuixiang2"] = "醒又醉，醉复眠，迟日江山如画，何人不流连。",
  ["~lvshi__pangtong"] = "落。。凤。。坡。。",
}

local weiyan = General(extension, "lvshi__weiyan", "shu", 4)
weiyan.strategy = "courage"

local jingao = fk.CreateTriggerSkill{
  name = "lvshi__jingao",
  anim_type = "offensive",
  events = {fk.AfterCardTargetDeclared},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target:inMyAttackRange(player) and data.tos and #data.tos > 0
    and not table.contains(U.getActualUseTargets(player.room, data, event), player.id) and
    ((data.card.type == Card.TypeTrick and data.card.sub_type ~= Card.SubtypeDelayedTrick) or data.card.trueName == "slash")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = player.room:askForDiscard(player, 1, 1, false, self.name, true, ".",
    "#lvshi__jingao-invoke:::"..data.card:toLogString())
    if #card > 0 then
      data.from = player.id
    else
      player:drawCards(1, self.name)
      data.tos = {{player.id}}
    end
  end,
}

local qimou = fk.CreateTriggerSkill{
  name = "lvshi__qimou",
  anim_type = "drawcard",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)-- and player:getMark("@@lvshi__qimou") == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local max = 0
    for _, p in ipairs(room.alive_players) do
      max = math.max(max, p:getHandcardNum())
    end
    player:drawCards(math.max(1, max - player:getHandcardNum()))
    room:addPlayerMark(player, "@@lvshi__qimou")
  end,

  refresh_events = {fk.Damage, fk.TurnStart},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:getMark("@@lvshi__qimou") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@lvshi__qimou", 0)
  end,
}

local qimou_attackrange = fk.CreateAttackRangeSkill{
  name = "#lvshi__qimou_attackrange",
  within_func = function (self, from, to)
    return to:hasSkill(self) and to:getMark("@@lvshi__qimou") > 0 and from ~= to
  end,
}

qimou:addRelatedSkill(qimou_attackrange)
weiyan:addSkill(jingao)
weiyan:addSkill(qimou)

Fk:loadTranslationTable{
  ["lvshi__weiyan"] = "魏延",
  ["#lvshi__weiyan"] = "气壮云长",
  ["designer:lvshi__weiyan"] = "氯",
  ["illustrator:lvshi__weiyan"] = "蚂蚁君",
  ["lvshi__jingao"] = "矜高",
  [":lvshi__jingao"] = "当攻击范围内有你的角色使用【杀】或通常锦囊牌时，若目标不包括你，你可选择一项：1.弃置一张牌，成为此牌的使用者；2.摸一张牌，成为此牌的唯一目标。",
  ["#lvshi__jingao-invoke"] = "你可以弃置一张牌并成为%arg的使用者，或选择取消，摸一张牌成为%arg的目标",

  ["lvshi__qimou"] = "奇谋",
  [":lvshi__qimou"] = "回合开始时，你可将手牌数摸至场上最大，然后你视为在所有其他角色攻击范围内直到你下回合开始或造成一次伤害。",
  ["@@lvshi__qimou"] = "奇谋",

  ["$lvshi__jingao1"] = "十万之众至，请为大王拒之。",
  ["$lvshi__jingao2"] = "魏延在此，汝辈何敢乃尔？",
  ["$lvshi__qimou1"] = "兵行死地方建功，敢笑诸葛不丈夫！",
  ["$lvshi__qimou2"] = "战机稍纵即逝，怎可犹豫不前！",
  ["~lvshi__weiyan"] = "谁来还吾清白？",
}

local jiangwei = General(extension, "lvshi__jiangwei", "shu", 4)
jiangwei.strategy = "schemecourage"
local lvshi__tianfu = fk.CreateViewAsSkill{
  name = "lvshi__tianfu",
  pattern = "dismantlement,nullification",
  interaction = function(self, player)
    local all_names = {"dismantlement", "nullification"}
    local names = {}
    local ids = Fk:currentRoom():getBanner("@$CenterArea") or {}
    local reds = #table.filter(ids, function(id) return Fk:getCardById(id).color == Card.Red end)
    local blacks = #table.filter(ids, function(id) return Fk:getCardById(id).color == Card.Black end)
    if blacks > reds then
      table.insert(names, "dismantlement")
    elseif reds > blacks then
      table.insert(names, "nullification")
    end
    local invoke_names = table.filter(U.getAllCardNames("t"), function (name)
      return table.contains(names, Fk:cloneCard(name).trueName)
    end)
    return U.CardNameBox { choices = invoke_names, all_choices = all_names }
  end,
  card_filter = function(self, to_select, selected, player)
    if Fk.currentResponsePattern == "nullification" then
      return Fk:getCardById(to_select).color == Card.Black
    elseif Fk.currentResponsePattern == nil then
      return Fk:getCardById(to_select).color == Card.Red
    end
  end,
  view_as = function(self, cards)
    if #cards ~= 1 or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(cards)
    card.skillName = self.name
    return card
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name) == 0
  end,
  enabled_at_response = function(self, player, response)--FIXME：pattern解析目前有问题
    return player:usedSkillTimes(self.name) == 0 and not response
  end
}

local tianfu_trigger = fk.CreateTriggerSkill{
  name = "#lvshi__tianfu_trigger",
  mute = true,
  events = {fk.CardUsing, fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and data.card.skillName == "lvshi__tianfu" and player.room:getBanner("@$CenterArea")
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local ids = player.room:getBanner("@$CenterArea") or {}
    local reds = #table.filter(ids, function(id) return Fk:getCardById(id).color == Card.Red end)
    local blacks = #table.filter(ids, function(id) return Fk:getCardById(id).color == Card.Black end)
    if event == fk.CardUseFinished and data.card.trueName == "nullification" then
      player:drawCards(reds, self.name)
    elseif event == fk.CardUsing and data.card.trueName == "dismantlement" and blacks > 1 then
      data.additionalEffect = (data.additionalEffect or 0) + blacks - 1
    end
  end,
}

local lvshi__zhiji = fk.CreateTriggerSkill{
  name = "lvshi__zhiji",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      local ids = player.room:getBanner("@$CenterArea") or {}
      local reds = #table.filter(ids, function(id) return Fk:getCardById(id).color == Card.Red end)
      local blacks = #table.filter(ids, function(id) return Fk:getCardById(id).color == Card.Black end)
      return reds == blacks
    end
  end,
  on_use = function(self, event, target, player, data)
    if not player:isWounded() then
      player.room:askForGuanxing(player, player.room:getNCards(3), nil, nil)
    end
    player.room:changeMaxHp(player, -1)
    player:gainAnExtraTurn()
  end,
}

lvshi__tianfu:addRelatedSkill(tianfu_trigger)
lvshi__tianfu.CenterArea = true
lvshi__zhiji.CenterArea = true
jiangwei:addSkill(lvshi__tianfu)
jiangwei:addSkill(lvshi__zhiji)

Fk:loadTranslationTable{
  ["lvshi__jiangwei"] = "姜维",
  ["#lvshi__jiangwei"] = "斜日沉声",
  ["designer:lvshi__jiangwei"] = "拼+宣+氯",
  ["lvshi__tianfu"] = "天覆",
  [":lvshi__tianfu"] = "回合技，若中央区黑/红色牌较多，你可将红/黑色牌当结算等量次的【过河拆桥】/结算后摸等量牌的【无懈可击】使用。",
  ["lvshi__zhiji"] = "志继",
  [":lvshi__zhiji"] = "一名角色的回合结束时，若中央区内红色牌的数量等于黑色牌的数量，你可减1点体力上限，进行一个额外的回合，若你未受伤，你先卜算3。",
  ["@red-turn"] = "红色",
  ["@black-turn"] = "黑色",

  ["$lvshi__tianfu1"] = "效逐日之夸父，怀忠志而长存。",
  ["$lvshi__tianfu2"] = "知天命而不顺，履穷途而强为。",
  ["$lvshi__zhiji1"] = "此身为薪，炬成灰亦昭大汉长明！",
  ["$lvshi__zhiji2"] = "维之一腔骨血，可驱驰来北马否？",
  ["~lvshi__jiangwei"] = "姜维姜维，又将何为？",
}

local sunce = General(extension, "lvshi__sunce", "wu", 4)
sunce.strategy = "courage"

local jiang = fk.CreateTriggerSkill{
  name = "lvshi__jiang",
  anim_type = "control",
  events = {fk.TargetSpecified, fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    local victim = player.room:getPlayerById(data.to)
    if event == fk.TargetConfirmed then
      victim = player.room:getPlayerById(data.from)
    end
    return target == player and player:hasSkill(self) and player ~= victim and
     (data.card.trueName == "slash" or data.card.trueName == "duel") and not victim:isNude() and not victim.dead
  end,
  on_cost = function(self, event, target, player, data)
    local victim = data.to
    if event == fk.TargetConfirmed then
      victim = data.from
    end
    if player.room:askForSkillInvoke(player, self.name, data, "#lvshi__jiang-invoke:"..victim) then
      self.cost_data = victim
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = player.room:getPlayerById(self.cost_data)
    local card = room:askForCard(to, 1, 1, true, self.name, false, ".", "#lvshi__jiang-give:"..player.id)
    room:obtainCard(player.id, card[1], false, fk.ReasonGive)
    if Fk:getCardById(card[1]).color == data.card.color then
      room:askForDiscard(player, 1, 1, false, self.name, false)
      room:addCardMark(data.card, "zhihengs_buff")
    end
  end,

  refresh_events = {fk.CardUseFinished},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and (data.card.trueName == "slash" or data.card.trueName == "duel")
     and data.card:getMark("zhihengs_buff") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:setCardMark(data.card, "zhihengs_buff", 0)
    local use = room:askForUseCard(player, "slash", "slash", "#lvshi__jiang-use", true,
    { bypass_distances = true, bypass_times = true })
    if use then
      room:useCard(use)
    end
  end
}

local hunshang = fk.CreateTriggerSkill{
  name = "lvshi__hunshang",
  frequency = Skill.Compulsory,
  anim_type = "drawcard",
  events = {fk.DrawNCards},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return ls.isFriend(target, player) and player.hp <= 1 and player:hasSkill(self, true, true)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:notifySkillInvoked(player, self.name, "drawcard")
    if player.dead then
      player:broadcastSkillInvoke(self.name, 3)
    else
      player:broadcastSkillInvoke(self.name, table.random({1,2}))
    end
    data.n = data.n + 1
  end,
}

local lvshi__bashi = fk.CreateTriggerSkill{
  name = "lvshi__bashi$",
  anim_type = "offensive",
  events = {fk.TargetSpecifying},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card.trueName == "slash" and data.tos
    and #AimGroup:getAllTargets(data.tos) == 1 and player:usedSkillTimes(self.name) == 0 then
      local targets = U.getUseExtraTargets(player.room, data, false, true)
      targets = table.filter(targets, function(p) return player.room:getPlayerById(p):getMark("ls__bashi-turn") > 0
        or table.contains(player:getTableMark("@[player]bashi"), p) end)
      return #targets > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    local targets = U.getUseExtraTargets(player.room, data, false, true)
    targets = table.filter(targets, function(p)
      return player.room:getPlayerById(p):getMark("ls__bashi-turn") > 0 or table.contains(player:getTableMark("@[player]bashi"), p) end)
    local tos = player.room:askForChoosePlayers(player, targets, 1, 999, "#ls__bashi-choose:::"..data.card:toLogString(), self.name, true)
    if #tos > 0 then
      self.cost_data = tos
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, pid in ipairs(self.cost_data) do
      AimGroup:addTargets(room, data, pid)
    end
    room:sendLog{
      type = "#AddTargetsBySkill",
      from = player.id,
      to = self.cost_data,
      arg = self.name,
      arg2 = data.card:toLogString()
    }
  end,

  refresh_events = {fk.TargetConfirmed},
  can_refresh = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(self) and data.card.trueName == "slash"
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addPlayerMark(target, "ls__bashi-turn")
    local from = player.room:getPlayerById(data.from)
    if from.kingdom == "wu" and from ~= player then
      player.room:addTableMark(player, "@[player]bashi", target.id)
    end
  end
}

sunce:addSkill(jiang)
sunce:addSkill(hunshang)
sunce:addSkill(lvshi__bashi)

Fk:loadTranslationTable{
  ["lvshi__sunce"] = "孙策",
  ["#lvshi__sunce"] = "号霸觅鼎",
  ["designer:lvshi__sunce"] = "氯",
  ["lvshi__jiang"] = "猘横",
  [":lvshi__jiang"] = "当你使用【杀】或【决斗】指定目标或成为【杀】或【决斗】的目标后，你可令对方交给你一张牌，若与此牌颜色相同，则你须弃置一张手牌，且你于此牌结算后可使用一张【杀】。",
  ["#lvshi__jiang-invoke"] = "猘横：你可令%src交给你一张牌",
  ["#lvshi__jiang-give"] = "猘横：你须交给%src一张牌",
  ["#lvshi__jiang-use"] = "猘横：你可使用一张【杀】。",
  ["lvshi__hunshang"] = "魂殇",
  [":lvshi__hunshang"] = "法则技，若你的体力值不大于1，己方角色于摸牌阶段多摸一张牌。",
  ["lvshi__bashi"] = "霸世",
  ["@[player]bashi"] = "霸世",
  [":lvshi__bashi"] = "主公技，回合技，你使用【杀】时可额外选择任意名此回合成为过【杀】目标的角色为目标，当有角色成为其他吴势力角色使用【杀】的目标后，其永久视为满足条件。",
  ["#ls__bashi-choose"] = "你可以为%arg额外增加任意个目标",
  ["#AddTargetsBySkill"] = "用于 %arg 的效果，%from 使用的 %arg2 增加了目标 %to",

  ["$lvshi__jiang1"] = "剑锋所指，敌莫敢当！",
  ["$lvshi__jiang2"] = "所向披靡，进退自如！",
  ["$lvshi__hunshang1"] = "（孙策存活）吾等戮力同心，定能回天转日！",
  ["$lvshi__hunshang2"] = "（孙策存活）孙家子弟，皆是善战之辈！",
  ["$lvshi__hunshang3"] = "（孙策阵亡）壮士不死则已，死，必扬名！",
  ["$lvshi__bashi1"] = "沙场百战疾，争衡天下间。",
  ["$lvshi__bashi2"] = "征战无休，决胜千里。",
  ["~lvshi__sunce"] = "忘川桥头千帆过，我自领兵斗阎罗！",
}

local sunquan = General(extension, "lvshi__sunquan", "wu", 4)
sunquan.strategy = "scheme"
local lvshi__zhiheng = fk.CreateActiveSkill{
  name = "lvshi__zhiheng",
  prompt = "#lvshi__zhiheng_trigger",
  anim_type = "drawcard",
  max_phase_use_time = 1,
  target_num = 0,
  min_card_num = 1,
  on_use = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    local more = 0
    if (table.every(from:getCardIds("h"), function (id) return table.contains(effect.cards, id) end) and #from:getCardIds("h") > 0)
    or (table.every(from:getCardIds("e"), function (id) return table.contains(effect.cards, id) end) and #from:getCardIds("e") > 0) then
      more = more + 1
    end
    room:throwCard(effect.cards, self.name, from)
    local n = #effect.cards + more
    if more == 0 and room:askForSkillInvoke(from, self.name, nil, "#lvshi__zhiheng") then
      n = n - 1
      from:setSkillUseHistory(self.name, 0, Player.HistoryPhase)
    end
    room:drawCards(from, n, self.name)
  end
}

local lvshi__tongye = fk.CreateTriggerSkill{
  name = "lvshi__tongye$",
  anim_type = "drawcard",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return target.kingdom == "wu" and player:hasSkill(self.name) and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(target, self.name, nil, "#lvshi__tongye:"..player.id)
  end,
  on_use = function(self, event, target, player, data)
    player.room:askForUseActiveSkill(player, "lvshi__zhiheng", "#lvshi__zhiheng")
    player:broadcastSkillInvoke("lvshi__zhiheng")
  end,
}

sunquan:addSkill(lvshi__zhiheng)
sunquan:addSkill(lvshi__tongye)

Fk:loadTranslationTable{
  ["lvshi__sunquan"] = "孙权",
  ["#lvshi__sunquan"] = "轻冠镇江",
  ["designer:lvshi__sunquan"] = "浩潇-淼龙",
  ["lvshi__zhiheng"] = "制衡",
  ["#lvshi__zhiheng_trigger"] = "你可以弃置至少一张牌，摸等量的牌",
  [":lvshi__zhiheng"] = "阶段技，你可弃置至少一张牌，摸等量的牌，若你弃置了一个区域内所有的牌，你多摸一张牌；否则你可少摸一张牌并重置此技能。",
  ["#lvshi__zhiheng"] = "你可以少摸一张牌，重置制衡",
  ["lvshi__tongye"] = "统业",
  [":lvshi__tongye"] = "主公技，吴势力角色的回合结束时，可令你发动一次“制衡”。",
  ["#lvshi__tongye"] = "你可以令%src发动“制衡”",

  ["$lvshi__zhiheng1"] = "多思多谋，筹谋长远。",
  ["$lvshi__zhiheng2"] = "不偏不倚，制而取衡。",
  ["$lvshi__zhiheng3"] = "息兵，等待时机，再战不迟。",
  ["$lvshi__tongye1"] = "惠用张仪，昭得范雎，朕拥卿足矣！",
  ["$lvshi__tongye2"] = "南靖交越，北复荆襄，使吴成帝业。",
  ["~lvshi__sunquan"] = "江东地方皆我父兄所创，权恨未扩疆半尺。",
}

local zhouyu = General(extension, "lvshi__zhouyu", "wu", 3, 4)
zhouyu.strategy = "schemecourage"

local lvshi__yingzi = fk.CreateTriggerSkill{
  name = "lvshi__yingzi",
  events = {fk.BeforeDrawCard},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data.num = data.num + 1
    --data.num = 3
  end,
}

local lvshi__yanyu = fk.CreateActiveSkill{
  name = "lvshi__yanyu",
  anim_type = "offensive",
  min_card_num = 1,
  max_card_num = 4,
  target_num = 0,
  prompt = "请选择任意张花色各不同的牌",
  can_use = function(self, player)
    return player:getMark("@@lvshi_readying:::"..self.name) == 0
  end,
  card_filter = function(self, to_select, selected)
    --return Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
    if Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand then
      local card = Fk:getCardById(to_select)
      return card.suit ~= Card.NoSuit and table.every(selected, function (id) return card.suit ~= Fk:getCardById(id).suit end)
    end
  end,
  target_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:showCards(effect.cards)
    room:setPlayerMark(player, "yanyu-prohibit", effect.cards)
    for i = 1, #effect.cards do
      local n = #effect.cards + 1 - i
      U.askForUseVirtualCard(room, player, "lvshi__fire_attack", nil, self.name, "#lvshi__yanyu:::"..n)
    end
    room:setPlayerMark(player, "yanyu-prohibit", 0)
  end,
}

local yanyu_prohibit = fk.CreateProhibitSkill{
  name = "#ls__yanyu_prohibit",
  prohibit_discard = function(self, player, card)
    return #player:getTableMark("yanyu-prohibit") > 0 and not table.contains(player:getTableMark("yanyu-prohibit"), card:getEffectiveId())
  end,
}

local lvshi__jiandi = fk.CreateActiveSkill{
  name = "lvshi__jiandi",
  prompt = "#lvshi__jiandi",
  anim_type = "offensive",
  max_phase_use_time = 1,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, _, _, _, player)
    if #selected < 2 then
      local target = Fk:currentRoom():getPlayerById(to_select)
      return #selected == 0 or not target:isKongcheng()
    end
  end,
  target_num = 2,
  card_num = 0,
  on_use = function(self, room, use)
    local player = room:getPlayerById(use.from)
    local from = room:getPlayerById(use.tos[1])
    local to = room:getPlayerById(use.tos[2])
    if to:isKongcheng() then return end
    local cid = room:askForCardChosen(from, to, "h", self.name)
    room:obtainCard(use.tos[1], cid, true, fk.ReasonPrey)
    if from.dead then return end
    from:showCards(cid)
    local suit = Fk:getCardById(cid).suit
    local suitString = Fk:getCardById(cid):getSuitString(true)
    local choices = { "ex__fanjian_show:::" .. suitString, "loseHp" }
    if from.hp <= 0 then table.remove(choices) end
    if (from:isKongcheng() and table.every(from:getCardIds(Player.Equip), function (id)
      return Fk:getCardById(id).suit ~= suit
    end)) or suit == Card.NoSuit then table.remove(choices, 1) end
    if #choices == 0 then return end
    local choice = room:askForChoice(player, choices, self.name)
    if choice == "loseHp" then
      room:loseHp(from, 1, self.name)
    else
      local cards = from:getCardIds(Player.Hand)
      if from.dead then return end
      local discards = table.filter(from:getCardIds("he"), function(id)
        return Fk:getCardById(id).suit == suit and not from:prohibitDiscard(Fk:getCardById(id))
      end)
      room:throwCard(discards, self.name, from, from)
    end
  end,
  target_tip = function(self, to_select, selected, _, __, selectable, ____)
    if not selectable then return end
    if #selected == 0 or (#selected > 0 and selected[1] == to_select) then
      return "jiandi_tip_1"
    else
      return "jiandi_tip_2"
    end
  end,
}

lvshi__yanyu:addRelatedSkill(yanyu_prohibit)
lvshi__yanyu.XushiSkill = true

zhouyu:addSkill(lvshi__yingzi)
zhouyu:addSkill(lvshi__yanyu)
--zhouyu:addSkill(lvshi__jiandi)

Fk:loadTranslationTable{
  ["lvshi__zhouyu"] = "周瑜",
  ["#lvshi__zhouyu"] = "炎神观阵",
  ["designer:lvshi__zhouyu"] = "氯",
  ["cv:lvshi__zhouyu"] = "王者荣耀",
  ["lvshi__yingzi"] = "英姿",
  [":lvshi__yingzi"] = "锁定技，你摸牌时额外摸一张牌。",
  --[":lvshi__yingzi"] = "锁定技，你摸牌时改为摸三张牌。",
  ["lvshi__yanyu"] = "焱狱",
  ["#ls__yanyu_prohibit"] = "焱狱",
  [":lvshi__yanyu"] = "<a href='lvshi_xushi_skill'>蓄势技</a>，出牌阶段，你可展示任意张花色各不同的手牌，视为使用等量张【火攻】，且你于结算中不能弃置其余牌。",
  ["#lvshi__yanyu"] = "焱狱：你可视为使用【火攻】（剩余%arg次）",
  ["@@lvshi_readying:::lvshi__yanyu"] = "焱狱行置",
  ["lvshi__jiandi"] = "间敌",
  [":lvshi__jiandi"] = "阶段技，你可选择两名角色，前者获得后者的一张手牌并展示，然后你令其执行一项：1.弃置与之花色相同的所有牌；2.失去1点体力。",
  ["#lvshi__jiandi"] = "请选择两名角色，前者获得后者的一张手牌",
  ["ex__fanjian_show"] = "展示手牌，弃置所有的%arg牌",
  ["jiandi_tip_1"] = "获得牌",
  ["jiandi_tip_2"] = "被获得牌",

  ["$lvshi__yingzi"] = "与我生在同一个时代，真是你们的不幸。",
  ["$lvshi__jiandi"] = "用头脑，而不是武力。",
  ["$lvshi__yanyu1"] = "燃起来吧！",
  ["$lvshi__yanyu2"] = "弹指间，灰飞烟灭！",
  ["~lvshi__zhouyu"] = "既生瑜，何生亮...",
}

local chengpu = General(extension, "lvshi__chengpu", "wu", 4)
chengpu.strategy = "courage"

local chunyi = fk.CreateActiveSkill{
  name = "lvshi__chunyi",
  anim_type = "support",
  prompt = "#lvshi__chunyi",
  target_num = 1,
  min_card_num = 1,
  max_card_num = 2,
  max_phase_use_time = 1,
  card_filter = function(self, to_select)
    return Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
  end,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and Self.id ~= to_select and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local cards = room:askForCard(target, 1, 2, false, self.name, false)
    local pattern = "lvs_fire__slash"
    if #effect.cards == #cards then
      pattern = "analeptic"
    end
    U.swapCards(room, player, player, target, effect.cards, cards, self.name)
    U.askForUseVirtualCard(room, player, pattern, nil, self.name, nil, true, false, false, false)
  end,
}

local dangkou = fk.CreateTriggerSkill{
  name = "lvshi__dangkou",
  anim_type = "switch",
  switch_skill_name = "lvshi__dangkou",
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self.name) and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 then
      if player:getSwitchSkillState(self.name, false) == fk.SwitchYang then
        return data.damage > 1
      elseif player:getSwitchSkillState(self.name, false) == fk.SwitchYin then
        return data.damageType == fk.FireDamage
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local targets = table.map(table.filter(player.room:getOtherPlayers(player), function(p)
      return p ~= data.to end), function (p) return p.id end)
    local prompt = "#lvshi__dangkou-choose1"
    if player:getSwitchSkillState(self.name, false) == fk.SwitchYin then
      prompt = "#lvshi__dangkou-choose2"
    end
    local to = player.room:askForChoosePlayers(player, targets, 1, 1, prompt, self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local n,m
    if player:getSwitchSkillState(self.name, true) == fk.SwitchYang then
      n = 1
      m = 3
    elseif player:getSwitchSkillState(self.name, true) == fk.SwitchYin then
      n = 2
      m = 1
    end
    player.room:damage({
      from = player,
      to = player.room:getPlayerById(self.cost_data),
      damage = n,
      damageType = m,
      skillName = self.name,
    })
  end,
}

chengpu:addSkill(chunyi)
chengpu:addSkill(dangkou)

Fk:loadTranslationTable{
  ["lvshi__chengpu"] = "程普",
  ["#lvshi__chengpu"] = "三朝虎首",
  ["designer:lvshi__chengpu"] = "拉+猪",
  ["lvshi__chunyi"] = "醇义",
  [":lvshi__chunyi"] = "阶段技，你可与一名其他角色同时选择一至两张手牌交换，若数量相同/不同，则你可视为使用【酒】/火【杀】。",
  ["#lvshi__chunyi"] = "醇义：请选择至多两张手牌和一名角色",
  ["lvshi__dangkou"] = "荡寇",
  [":lvshi__dangkou"] = "回合技，转换技，①当你一次造成至少2点伤害后，你可对另一名其他角色造成1点火焰伤害；②当你造成火焰伤害后，你可对另一名角色造成2点伤害。",
  ["#lvshi__dangkou-choose1"] = "荡寇：请选择一名角色，对其造成1点火焰伤害",
  ["#lvshi__dangkou-choose2"] = "荡寇：请选择一名角色，对其造成2点伤害",

  ["$lvshi__dangkou1"] = "叛军者，非烈火灼身难泄吾恨。",
  ["$lvshi__dangkou2"] = "投敌于火，烧炙其身，皮焦肉烂！",
  ["$lvshi__chunyi1"] = "醉里披甲执坚，梦中杀敌破阵。",
  ["$lvshi__chunyi2"] = "醇醪须与明君饮，沙场无还亦不悔。",
  ["~lvshi__chengpu"] = "病疠缠身，终天命难违。",
}

local zhangzhao = General(extension, "lvshi__zhangzhao", "wu", 3)
zhangzhao.strategy = "scheme"
local lvshi__zhengyan = fk.CreateActiveSkill{
  name = "lvshi__zhengyan",
  anim_type = "support",
  prompt = "#lvshi__zhengyan-active",
  card_num = 1,
  target_num = 1,
  can_use = Util.TrueFunc,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and ((Fk:getCardById(to_select).type == Card.TypeEquip and Fk:currentRoom():getCardArea(to_select) ~= Player.Equip)
    or Fk:getCardById(to_select).trueName == "peach")
  end,
  target_filter = function (self, to_select, selected, cards, _, _, player)
    return #selected == 0 and #cards == 1 and player.id ~= to_select 
    and (Fk:getCardById(cards[1]).type == Card.TypeEquip or Fk:currentRoom():getPlayerById(to_select):isWounded())
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local card = Fk:getCardById(effect.cards[1])
    if not player:isProhibited(target, card) then
      room:useCard({
        card = card,
        from = player.id,
        tos = {{target.id}},
        skillName = self.name,
      })
    end
  end,
}

local zhengyan_buff = fk.CreateTriggerSkill{
  name = "#lvshi__zhengyan_trigger",
  mute = true,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and #TargetGroup:getRealTargets(data.tos) > 0
    and table.find(TargetGroup:getRealTargets(data.tos), function(id) return ls.isFriend(player, player.room:getPlayerById(id)) end)
  end,
  on_cost = function(self, event, target, player, data)
    local to = player.room:askForChoosePlayers(target, table.map(table.filter(player.room:getOtherPlayers(target), function(p)
      return not p:isNude() end), function(p) return p.id end), 1, 1, "#lvshi__zhengyan-choose", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("lvshi__zhengyan")
    local id = room:askForCardChosen(target, room:getPlayerById(self.cost_data), "he", self.name)
    room:throwCard({id}, self.name, room:getPlayerById(self.cost_data), target)   
  end,
}

local lvshi__zuozheng = fk.CreateTriggerSkill{
  name = "lvshi__zuozheng",
  mute = true,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and target.phase == Player.Discard
  end,
  on_cost = function(self, event, target, player, data)
    if target == player then
      return player.room:askForSkillInvoke(player, self.name)
    else
      return player.room:askForSkillInvoke(player, self.name, nil, "#lvshi__zuozheng-invoke::"..target.id)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, self.name, "drawcard")
    if string.find(player.general, "zhugejin") then
      player:broadcastSkillInvoke(self.name, 2)
    else
      player:broadcastSkillInvoke(self.name, 1)
    end
    player:drawCards(2, self.name)
    if player ~= target and not player:isNude() then
      local cards
      if #player:getCardIds("he") <= 2 then
        cards = player:getCardIds("he")
      else
        cards = room:askForCard(player, 2, 2, true, self.name, false, ".", "#lvshi__zuozheng-give::"..target.id)
      end
      if #cards > 0 then
        room:moveCardTo(cards, Card.PlayerHand, target, fk.ReasonPrey, self.name, "", true, player.id)
      end
    end
    --U.askForPlayCard(room, target, target:getHandlyIds(true), ".", self.name)
    room:askForUseActiveSkill(target, "lvshi__zuozheng_throw", "#lvshi__zuozheng", false, false)
    return true
  end,
}

local zuozheng__throw = fk.CreateActiveSkill{
  name = "lvshi__zuozheng_throw",
  --anim_type = "drawcard",
  mute = true,
  can_use = function(self, player)
    return false
  end,
  target_num = 0,
  min_card_num = 1,
  max_card_num = 4,
  card_filter = function(self, to_select, selected)
    if #selected == 0 then
      return Fk:currentRoom():getCardArea(to_select) == Player.Hand
    elseif Fk:currentRoom():getCardArea(to_select) == Player.Hand then
      return table.every(selected, function (id) return Fk:getCardById(to_select).suit ~= Fk:getCardById(id).suit end)
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local discards = table.filter(player:getCardIds({Player.Hand}), function(id)
      return not table.contains(effect.cards, id)
    end)
    room:throwCard(discards, self.name, player, player)
  end
}

Fk:addSkill(zuozheng__throw)

lvshi__zhengyan:addRelatedSkill(zhengyan_buff)
zhangzhao:addSkill(lvshi__zhengyan)
zhangzhao:addSkill(lvshi__zuozheng)

Fk:loadTranslationTable{
  ["lvshi__zhangzhao"] = "张昭",
  ["#lvshi__zhangzhao"] = "民望布阳",
  ["designer:lvshi__zhangzhao"] = "氯",
  ["lvshi__zhengyan"] = "铮言",
  [":lvshi__zhengyan"] = "你使用【桃】或装备牌可选择其他角色为目标；当你使用牌结算后，若之目标包括己方角色，你可弃置一名其他角色的一张牌。",
  ["#lvshi__zhengyan-active"] = "你可以选择【桃】或装备牌和一名其他角色",
  ["#lvshi__zhengyan-choose"] = "铮言：你可弃置一名其他角色的一张牌",
  ["lvshi__zuozheng"] = "佐政", 
  [":lvshi__zuozheng"] = "一名角色的弃牌阶段开始时，你可摸两张牌并交给其两张牌，然后其于此阶段改为将手牌弃置至每种花色各一张。",
  ["#lvshi__zuozheng-invoke"] = "佐政：你可以摸两张牌，交给%dest两张牌", 
  ["#lvshi__zuozheng-give"] = "佐政：请选择交给%dest的牌", 
  ["lvshi__zuozheng_throw"] = "佐政", 
  ["#lvshi__zuozheng"] = "佐政：请选择保留的手牌，弃置其余牌", 

  ["$lvshi__zhengyan1"] = "陛下若此，天下何以观之！",
  ["$lvshi__zhengyan2"] = "偏听谄谀之言，此为万民所仰之君乎？",
  ["$lvshi__zhengyan3"] = "陛下欲复昔日桓公之事乎？",
  ["$lvshi__zuozheng_lvshi__zhangzhao"] = "君者当御贤于后，安可校勇于猛兽！",
  ["~lvshi__zhangzhao"] = "哼哼！此皆老臣罪责，陛下岂会有过。",	
  ["$lvshi__zuozheng_lsz__zhugejin"] = "后援即刻就到，诸将莫急！",
}

local lusu = General(extension, "lvshi__lusu", "wu", 3)
lusu.strategy = "scheme"

local zhitong = fk.CreateActiveSkill{
  name = "lvshi__zhitong",
  target_num = 2,
  card_num = 0,
  max_phase_use_time = 1,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local targets = table.map(effect.tos, Util.Id2PlayerMapper)
    local n = player:usedSkillTimes(self.name, Player.HistoryGame) + 1
    local result = U.askForJointCard(targets, 1, n, false, self.name, false, ".", "#lvshi__zhitong:"..effect.from)
    local cards = result[effect.tos[1]]
    table.insertTableIfNeed(cards, result[effect.tos[2]])
    room:obtainCard(player, cards, true, fk.ReasonGive, player.id, self.name)
    targets = table.filter(targets, function (p) return p:isAlive() end)
    room:askForYiji(player, player:getCardIds("h"), targets, self.name, #targets, n * #targets, "#lvshi__zhitong-give", nil, false, n)
    if targets[1]:getHandcardNum() == targets[2]:getHandcardNum() then
      room:recover{who = player, num = 1, recoverBy = player, skillName = self.name}
    end
  end
}

local daomeng = fk.CreateTriggerSkill{
  name = "lvshi__daomeng",
  mute = true,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and player.phase == Player.Discard
  end,
  on_cost = function(self, event, target, player, data)
    local targets = table.filter(player.room:getOtherPlayers(player), function (p)
      return ls.isFriend(player, p) and not p:isKongcheng()
    end)
    local to = player.room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#lvshi__daomeng-target", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      player.room:doIndicate(player.id, {to[1]})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, self.name, "support")
    if string.find(player.general, "zhugejin") then
      player:broadcastSkillInvoke(self.name, table.random({3,4}))
    else
      player:broadcastSkillInvoke(self.name, table.random({1,2}))
    end
    local to = room:getPlayerById(self.cost_data)
    U.swapHandCards(room, player, player, to, self.name)
    if player:getHandcardNum() ~= to:getHandcardNum() then
      local user,other
      if player:getHandcardNum() > to:getHandcardNum() then
        user = player
        other = to
      elseif player:getHandcardNum() < to:getHandcardNum() then
        user = to
        other = player
      end
      if user then
        U.askForUseVirtualCard(room, user, "slash", nil, self.name)
      end
      if other then
        local jinks = table.filter(room.discard_pile, function (id) return Fk:getCardById(id).trueName == "jink" end)
        if #jinks > 0 then
          local jink = table.random(jinks)
          room:obtainCard(other.id, jink, true, fk.ReasonJustMove)
        end
      end
    end
    room.current._phase_end = true
  end,
}

lusu:addSkill(zhitong)
lusu:addSkill(daomeng)

Fk:loadTranslationTable{
  ["lvshi__lusu"] = "鲁肃",
  ["#lvshi__lusu"] = "踏刃倾谈",
  ["designer:lvshi__lusu"] = "豪曹+氯",
  ["lvshi__zhitong"] = "志通",
  [":lvshi__zhitong"] = "阶段技，你可获得两名其他角色各一至X张手牌，然后交给这些角色各至多X张手牌，若这些角色的手牌数相同，你回复1点体力。（X为你发动此技能次数+1）",
  ["#lvshi__zhitong"] = "志通：请选择交给%src的手牌",
  ["#lvshi__zhitong-give"] = "志通：请选择分配的牌和角色，或取消继续分配",
  ["lvshi__daomeng"] = "蹈盟",
  [":lvshi__daomeng"] = "弃牌阶段，你可改为和一名己方角色交换手牌，然后手牌数较多的角色视为使用【杀】，手牌数较少的角色获得弃牌堆内一张【闪】。",
  ["#lvshi__daomeng-target"] = "蹈盟：你可以和一名己方角色交换手牌",

  ["$lvshi__daomeng_lvshi__lusu1"] = "联刘以抗曹，此可行之大势。",
  ["$lvshi__daomeng_lvshi__lusu2"] = "强敌在北，唯协力可御之。",
  ["$lvshi__zhitong1"] = "合左抑右，定两家之盟。",
  ["$lvshi__zhitong2"] = "求同存异，邀英雄问鼎。",
  ["~lvshi__lusu"] = "内忧外患，何日能消。",
  ["$ls__daomeng_lvshi__zhugejin1"] = "友邦和睦，民安阖乐。",
  ["$ls__daomeng_lvshi__zhugejin2"] = "盟友相护，毋需担忧。",
}

local lvmeng = General(extension, "lvshi__lvmeng", "wu", 4)
lvmeng.strategy = "schemecourage"

local ls__duxue = fk.CreateViewAsSkill{
  name = "lvshi__duxue",
  card_num = 0,
  pattern = "ex_nihilo",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).trueName == "slash"
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("ex_nihilo")
    card:addSubcards(cards)
    card.skillName = self.name
    return card
  end,
  enabled_at_play = function(self, player)
    return player:getHandcardNum() < player.hp
  end,
  enabled_at_response = Util.FalseFunc,
}

local ls__tanhu = fk.CreateActiveSkill{
  name = "lvshi__tanhu",
  anim_type = "control",
  prompt = "你可以展示一张【杀】或锦囊牌视为使用【探查】",
  target_num = 1,
  card_num = 1,
  max_phase_use_time = 1,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and (Fk:getCardById(to_select).type == Card.TypeTrick or Fk:getCardById(to_select).trueName == "slash")
  end,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    target:showCards(target:getCardIds("h"))
    local suit = Fk:getCardById(effect.cards[1]).suit
    local ids = table.filter(target:getCardIds("h"), function (id) return Fk:getCardById(id).suit == suit end)
    room:throwCard(ids, self.name, target, target)
  end,
}

local ls__botu = fk.CreateTriggerSkill{
  name = "lvshi__botu",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryRound) == 0 then
      local ids = player.room:getBanner("@$CenterArea")
      return ls.countSuits(ids) >= 4
    end
  end,
  on_use = function(self, event, target, player, data)
    player:gainAnExtraTurn()
  end,
}

ls__botu.CenterArea = true
lvmeng:addSkill(ls__duxue)
lvmeng:addSkill(ls__tanhu)
lvmeng:addSkill(ls__botu)

Fk:loadTranslationTable{
  ["lvshi__lvmeng"] = "吕蒙",
  ["#lvshi__lvmeng"] = "千帆隐渡",
  ["designer:lvshi__lvmeng"] = "氯",
  ["lvshi__duxue"] = "笃学",
  [":lvshi__duxue"] = "若你的手牌数小于体力值，你可将【杀】当【无中生有】使用。",
  ["lvshi__tanhu"] = "探虎",
  [":lvshi__tanhu"] = "阶段技，你可展示一张【杀】或锦囊牌并选择一名角色，其展示手牌并弃置其中与之花色相同的牌。",
  ["lvshi__botu"] = "博图",
  [":lvshi__botu"] = "轮次技，一名角色的回合结束后，若中央区内的牌花色数为4，则你可进行一个额外的回合。",

  ["$lvshi__duxue1"] = "手不释卷，学而广益。",
  ["$lvshi__duxue2"] = "治经勤学，别三日而刮目相看。",
  ["$lvshi__tanhu1"] = "此速攻可胜，切莫筑室道谋！",
  ["$lvshi__tanhu2"] = "生死存亡之道，不可不察！",
  ["$lvshi__botu"] = "书读五车，云开见日。",
  ["~lvshi__lvmeng"] = "病疾蚕躯，无力回天。",
}

local luxun = General(extension, "lvshi__luxun", "wu", 3)
luxun.strategy = "schemecourage"

local lvshi__wotao = fk.CreateViewAsSkill{
  name = "lvshi__wotao",
  prompt = "#lvshi__wotao",
  mute = true,
  pattern = "await_exhausted,nullification",
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    if #cards ~= 0 then return nil end
    local card = Fk:cloneCard("lvshi__await_exhausted")
    if Fk.currentResponsePattern == "nullification" then
      card = Fk:cloneCard("nullification")
    end
    card.skillName = self.name
    return card
  end,
  enabled_at_play = function(self, player)
    return player:getMark("@@lvshi_readying:::"..self.name) == 0
  end,
  enabled_at_response = function(self, player, response)
    if response then return false end
    return player:getMark("@@lvshi_readying:::"..self.name) == 0
  end,
  before_use = function(self, player, use)
    local n = 1 or (use.card.trueName == "nullification" and 2)
    local anim = "support" or (use.card.trueName == "nullification" and "control")
    player.room:notifySkillInvoked(player, self.name, anim)
    player:broadcastSkillInvoke(self.name, n)
  end,
}

local lvshi__yuezhen = fk.CreateTriggerSkill{
  name = "lvshi__yuezhen",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self.name) then return end
    if not player:isKongcheng() then return end
    for _, move in ipairs(data) do
      if move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand then
            return true
          end
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local n = 1
    if #table.filter(data, function(move) return #move.moveInfo > 1 end) then
      n = #data[1].moveInfo
    end
    local to = player.room:askForChoosePlayers(player, table.map(player.room.alive_players, function(p) return p.id end), 1, n, "#yuzhen-choose:::"..n, self.name, true)
    if #to > 0 then
      self.cost_data = to
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    for _, p in ipairs(self.cost_data) do
      player.room:getPlayerById(p):drawCards(1, self.name)
    end
  end,
}
lvshi__wotao.XushiSkill = true
luxun:addSkill(lvshi__wotao)
luxun:addSkill(lvshi__yuezhen)

Fk:loadTranslationTable{
  ["lvshi__luxun"] = "陆逊",
  ["#lvshi__luxun"] = "栋国儒身",
  ["designer:lvshi__luxun"] = "懂太师",
  ["lvshi__wotao"] = "握韬",
  [":lvshi__wotao"] = "<a href='lvshi_xushi_skill'>蓄势技</a>，当你需要使用【以逸待劳】或【无懈可击】时，你可视为使用之。",
  ["#lvshi__wotao"] = "你可以视为使用【以逸待劳】或【无懈可击】",
  ["@@lvshi_readying:::lvshi__wotao"] = "握韬行置",
  ["lvshi__yuezhen"] = "阅阵",
  [":lvshi__yuezhen"] = "当你失去所有手牌后，你可令至多X名角色各摸一张牌（X为你此次失去的手牌数）。",
  ["#yuzhen-choose"] = "阅阵：请选择%arg名角色",
  ["$lvshi__wotao1"] = "（以逸待劳）审时度势，切不可轻动。",
  ["$lvshi__wotao2"] = "（无懈可击）军略不止，良策不息。",
  ["$lvshi__yuezhen1"] = "手提玉剑斥千军，昔日锦鲤化金龙。",
  ["$lvshi__yuezhen2"] = "步步为营者，定无后顾之虞。",
  ["~lvshi__luxun"] = "一生戎马，不料竟被逼至此。",
}

local huanggai = General(extension, "lvshi__huanggai", "wu", 4)
huanggai.strategy = "courage"

local zhouyan = fk.CreateTriggerSkill{
  name = "lvshi__zhouyan",
  events = {fk.EventPhaseStart, fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player then
      if event == fk.EventPhaseStart then
        return player.phase == Player.Play
      else
        return data.damageType ~= fk.NormalDamage
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local pattern = "slash"
    if event == fk.EventPhaseStart then
      pattern = "fire_attack"
    else
      pattern = "iron_chain"
    end
    local names = table.filter(U.getAllCardNames('t'), function (len) return string.find(len, pattern) end)
    local cards = table.map(names, function (name) return player.room:printCard(name).id end)
    local use = U.askForUseRealCard(player.room, player, cards, nil, self.name, "#lvshi__zhouyan-use",
      {expand_pile = cards, bypass_times = true}, true, true)
    if use then
      self.cost_data = use
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local use = {
      card = Fk:cloneCard(self.cost_data.card.name),
      from = self.cost_data.from,
      tos = self.cost_data.tos,
      extraUse = true,
    }
    use.card.skillName = self.name
    player.room:useCard(use)
  end,
}

local zhaxiang = fk.CreateTriggerSkill{
  name = "lvshi__zhaxiang",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and target == player and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 
  end,
  on_use = function(self, event, target, player, data)
    data.from:drawCards(2, self.name)
    if not data.from:isKongcheng() then
      local id = player.room:askForCardChosen(player, data.from, {
        card_data = {
          {"$Hand", data.from:getCardIds("h")},
        }
      }, self.name)
      player:addToPile("shield", id, true, self.name)
    end
  end,
}

huanggai:addSkill(zhouyan)
huanggai:addSkill(zhaxiang)

Fk:loadTranslationTable{
  ["lvshi__huanggai"] = "黄盖",
  ["#lvshi__huanggai"] = "奋身出命",
  ["designer:lvshi__huanggai"] = "氯",
  ["lvshi__zhouyan"] = "舟焰",
  [":lvshi__zhouyan"] = "出牌阶段开始时，你可视为【火攻】；当你造成属性伤害时，可视为使用【铁索连环】。",
  ["#lvshi__zhouyan-use"] = "舟焰：请视为使用的牌",
  ["lvshi__zhaxiang"] = "诈降",
  [":lvshi__zhaxiang"] = "回合技，当你受到伤害后，你可令来源摸两张牌，然后你观看其手牌，将其一张手牌置为你的护甲。",
  ["$lvshi__zhouyan1"] = "烈酒洗长刀，屠尽天下敌！",
  ["$lvshi__zhouyan2"] = "怒火燎原，焚尽千里！",
  ["$lvshi__zhaxiang1"] = "若用此计，江东水军不足为惧。",
  ["$lvshi__zhaxiang2"] = "吾赤诚之心，愿丞相明了。",
  ["~lvshi__huanggai"] = "大江浪遏舟，老将叹奈何。",
}

local zhangjiao = General(extension, "lvshi__zhangjiao", "qun", 3)
zhangjiao.strategy = "scheme"

local lvshi__sijun = fk.CreateTriggerSkill{
  name = "lvshi__sijun",
  anim_type = "offensive",
  events = {fk.CardUsing, fk.FinishJudge, fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if event == fk.CardUsing then
      return player:hasSkill(self) and target == player and data.card.trueName == "jink"
    elseif event == fk.FinishJudge then
      return player:hasSkill(self) and target == player and player.room:getCardArea(data.card) == Card.Processing
      and data.card.suit == Card.Spade
    elseif event == fk.Damaged then
      return player:hasSkill(self) and data.damageType == fk.ThunderDamage and target ~= player and player:isWounded()
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.CardUsing or event == fk.FinishJudge then
      if player.room.current then
        return player.room:askForSkillInvoke(player, self.name, nil, "#lvshi__sijun-invoke:"..player.room.current.id)
      end
    else
      return true
    end
  end, 
  on_use = function(self, event, target, player, data)
   local room = player.room
   if event == fk.CardUsing or event == fk.FinishJudge then
    if room.current then
      room:damage{
        from = player,
        to = room.current,
        damage = 1,
        damageType = fk.ThunderDamage,
        skillName = self.name,
      }
    end
  elseif event == fk.Damaged then
    --[[local choices = {"lvshi__draw1"}
    if player:isWounded() then table.insertIfNeed(choices, "lvshi__heal") end
    local choice = room:askForChoice(player, choices, self.name, "", false, {"lvshi__heal","lvshi__draw1"})
    if choice == "lvshi__draw1" then
      player:drawCards(1, self.name)
    elseif choice == "lvshi__heal" then
    end]]
    room:recover({
      who = player,
      num = 1,
      recoverBy = player,
      skillName = self.name
    })
  end
end,
}

local lvshi__xuanhua = fk.CreateTriggerSkill{
  name = "lvshi__xuanhua",
  anim_type = "offensive",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target:inMyAttackRange(player)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#lvshi__hongfa-invoke::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnEnd then
      room:delay(500)
      local judge = {
        who = player,
        reason = self.name,
        pattern = ".",
      }
      room:judge(judge)
      local suits = player:getTableMark("@lvshi__xuanhua-round")
      if not table.contains(suits, judge.card:getSuitString(true)) then
        table.insert(suits, judge.card:getSuitString(true))
        room:obtainCard(player.id, judge.card, true, fk.ReasonJustMove)
        room:setPlayerMark(player, "@lvshi__xuanhua-round", suits)
      end
    end
  end,
}

local wuxin = fk.CreateTriggerSkill{
  name = "lvshi__wuxin$",
  anim_type = "control",
  events = {fk.AskForRetrial},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.kingdom == "qun" and data.card.color == Card.Black
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards(2)
    local ids, choice = U.askforChooseCardsAndChoice(player, cards, {"OK"}, self.name, "#lvshi__wuxin-ask::"..target.id)
    table.removeOne(cards, ids[1])
    room:retrial(Fk:getCardById(ids[1]), player, data, self.name)
    room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, "", true)
  end,
}

local wuxin_maxcards = fk.CreateMaxCardsSkill{
  name = "#lvshi__wuxin_maxcards",
  correct_func = function(self, player)
    if player:hasSkill(self) then
      --local num = #table.filter(Fk:currentRoom().alive_players, function (p) return p.kingdom ~= "qun" end)
      local kingdoms = {}
      for _, p in ipairs(Fk:currentRoom().alive_players) do
        table.insertIfNeed(kingdoms, p.kingdom)
      end
      return #kingdoms
    end
  end,
}

wuxin:addRelatedSkill(wuxin_maxcards)
zhangjiao:addSkill(lvshi__sijun)
zhangjiao:addSkill(lvshi__xuanhua)
zhangjiao:addSkill(wuxin)

Fk:loadTranslationTable{
  ["lvshi__zhangjiao"] = "张角",
  ["#lvshi__zhangjiao"] = "驱天覆世",
  ["designer:lvshi__zhangjiao"] = "请叫我宣宣",
  ["lvshi__sijun"] = "肆军",
  [":lvshi__sijun"] = "当你使用【闪】后或你的黑桃判定牌生效后，你可对当前回合角色造成1点雷电伤害；当其他角色受到雷电伤害后，你回复1点体力。",
  ["#lvshi__sijun-invoke"] = "你可对%src造成1点雷电伤害",
  ["lvshi__heal"] = "回复1点体力",
  ["lvshi__draw1"] = "摸一张牌",
  ["lvshi__xuanhua"] = "宣化",
  [":lvshi__xuanhua"] = "其他角色的回合结束后，若你在其攻击范围内，你可进行一次判定，若结果不为此轮判定过的花色，你获得之。",
  ["@lvshi__xuanhua-round"] = "宣化",
  ["#lvshi__hongfa-invoke"] = "宣化：你可进行一次判定",
  ["lvshi__wuxin"] = "悟心",
  [":lvshi__wuxin"] = "主公技，你的手牌上限增加非群势力数；群势力角色的黑色判定牌生效前，你可亮出牌堆两张牌，打出其中一张牌代替之。",
  ["#lvshi__wuxin-ask"] = "你可用其中一张牌代替%dest的判定牌",

  ["$lvshi__sijun1"] = "黄天挥军，四海皆应！",
  ["$lvshi__xuanhua1"] = "以道御术，以法灭阵！",
  ["$lvshi__xuanhua2"] = "拦我天工者，天诛之！",
  ["$lvshi__xuanhua3"] = "顺天应命，为我黄天！",
  ["~lvshi__zhangjiao"] = "黄巾基业，毁于一旦啊。。",

  ["$lvshi__wuxin1"] = "冀悟迷惑之心。",
  ["$lvshi__wuxin2"] = "吾已明此救世之术矣。",
}

local yuanshao = General(extension, "lvshi__yuanshao", "qun", 4)
yuanshao.strategy = "schemecourage"

local lvshi__junshi = fk.CreateViewAsSkill{
  name = "lvshi__junshi",
  pattern = ".|.|.|.|.|trick|.",
  prompt = "#lvshi__junshi",
  interaction = function(self)
    local all_names = U.getAllCardNames("t")
    local names = U.getViewAsCardNames(Self, self.name, all_names)
    if #names == 0 then return false end
    return U.CardNameBox { choices = names, all_choices = all_names }
  end,
  card_filter = function(self, to_select, selected, player)
    local card = Fk:getCardById(to_select)
    return #selected == 0 and (ls.getStrategy(player, false) ~= "none" or card.type == Card.TypeTrick)
  end,
  view_as = function(self, cards)
    if #cards ~= 1 or not self.interaction.data then return nil end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcard(cards[1])
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    use.card.canstrategy = true
    use.prohibitedCardNames = {"nullification"}
  end,
  after_use = function(self, player, use)
    local card = Fk:getCardById(use.card.subcards[1])
    if card.type ~= Card.TypeTrick then
      ls.loseStrategy(player, "choice")
    end
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  enabled_at_response = Util.FalseFunc,
}

local junshi_trigger = fk.CreateTriggerSkill{
  name = "#junshi_trigger",
  mute = true,
  refresh_events = {fk.AfterDrawPileShuffle},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_refresh = function(self, event, target, player, data)
    ls.resetStrategy(player)
  end,
}


local lvshi__xueyi = fk.CreateActiveSkill{
  name = "lvshi__xueyi$",
  anim_type = "offensive",
  card_num = 0,
  target_num = 1,
  prompt = "#lvshi__xueyi-active",
  can_use = function(self, player)
    return player:getMark("@lvshi__xueyi") > 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id and Fk:currentRoom():getPlayerById(to_select):getMark("@lvshi__xueyi") == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:removePlayerMark(player, "@lvshi__xueyi", 1)
    room:addPlayerMark(target, "@lvshi__xueyi", 1)
  end,

  on_lose = function(self, player)
    local room = player.room
    if table.every(room.alive_players, function (p)
      return not p:hasSkill(self, true)
    end) then
      for _, p in ipairs(room.alive_players) do
        room:setPlayerMark(p, "@lvshi__xueyi", 0)
      end
    end
  end,
}

local lvshi__xueyi_record = fk.CreateTriggerSkill{
  name = "#lvshi__xueyi_record",
  main_skill = lvshi__xueyi,
  anim_type = "offensive",
  events = {fk.GameStart, fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(lvshi__xueyi) then
      if event == fk.GameStart then
        return player:getMark("@lvshi__xueyi") == 0
      elseif event == fk.EnterDying then
        return target:getMark("@lvshi__xueyi") > 0 and data.who == target.id
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("lvshi__xueyi")
    if event == fk.GameStart then
      local n = #table.filter(room.players, function (p) return p.kingdom == "qun" end)
      room:setPlayerMark(player, "@lvshi__xueyi", n)
    else
      room:doIndicate(player.id, {target.id})
      room:removePlayerMark(target, "@lvshi__xueyi", 1)
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
      local choices = {}
      if not string.find(ls.getStrategy(player, false), "scheme") then table.insert(choices, "scheme") end
      if not string.find(ls.getStrategy(player, false), "courage") then table.insert(choices, "courage") end
      if #choices == 0 then return false end
      local choice = room:askForChoice(player, choices, self.name)
      ls.gainStrategy(player, choice)
    end
  end,
}

local xueyi_maxcards = fk.CreateMaxCardsSkill{
  name = "#lvshi__xuey_maxcards",
  correct_func = function(self, player)
    if player:getMark("@lvshi__xueyi") > 0 then
      return 2
    end
  end,
}

lvshi__junshi:addRelatedSkill(junshi_trigger)
lvshi__xueyi:addRelatedSkill(lvshi__xueyi_record)
lvshi__xueyi:addRelatedSkill(xueyi_maxcards)
yuanshao:addSkill(lvshi__junshi)
yuanshao:addSkill(lvshi__xueyi)

Fk:loadTranslationTable{
  ["lvshi__yuanshao"] = "袁绍",
  ["#lvshi__yuanshao"] = "声高天侧",
  ["designer:lvshi__yuanshao"] = "Erosa",
  ["lvshi__junshi"] = "军势",
  [":lvshi__junshi"] = "阶段技，你可将一张牌当不可被【无懈可击】响应的任意通常锦囊牌使用，你以此法转化牌时可发动你拥有的策略效果，且你转化底牌为非锦囊牌时需失去一个策略。牌堆切洗后，你恢复所有策略。",
  ["#lvshi__junshi"] = "军势：请选择一张牌和转化的牌名，然后确定",
  ["lvshi__xueyi"] = "血裔",
  ["#lvshi__xueyi_record"] = "血裔",
  ["@lvshi__xueyi"] = "裔",
  [":lvshi__xueyi"] = "主公技，游戏开始时，你获得X个“裔”标记（X为群雄角色数），出牌阶段，你可将1个“裔”标记交给一名没有“裔”的角色，拥有“裔”的角色手牌上限+2，且其进入濒死时，失去1个“裔”标记，然后你回复1点体力并获得一个策略。",
  ["#lvshi__xueyi-active"] = "你可将1个“裔”标记交给一名没有“裔”的角色",
  --["#lvshi__xueyi"] = "你可%src失去“裔”，回复1点体力",

  ["$lvshi__junshi1"] = "居北望南，天下碌碌之辈，诚不足虑也。", 
  ["$lvshi__junshi2"] = "驱韩缚马，擒尔雄兵十万，不过覆手之间。", 
  ["$lvshi__xueyi1"] = "四世三公之家，当为天下之望。", 
  ["$lvshi__xueyi2"] = "大势在我，可怀问鼎之心。", 
  ["~lvshi__yuanshao"] = "纵横天下二十载，霸业说与山鬼听。",
}

local dongzhuo = General(extension, "lvshi__dongzhuo", "qun", 4)
dongzhuo.strategy = "courage"
local lvshi__hengzheng = fk.CreateTriggerSkill{
  name = "lvshi__hengzheng",
  anim = "offensive",
  events = {fk.EventPhaseStart},
  dynamic_desc = function(self, player)
    local texts = {"ls__hengzheng_inner", "", "lvshi__hengzheng1", "", "lvshi__hengzheng2", "", "lvshi__hengzheng3", "</font>", "", "hengzheng_tail"}
    local x = 0
    for i = 1, 3, 1 do
      if player:getMark("ls__hengzheng" .. tostring(i)) > 0 then
        texts[2 * i] = "ls__hengzheng_color"
        x = x + 1
      end
    end
    if player:getMark("hengzhengedit") > 0 then
      texts[9] = "hengzhengedit"
    end
    return (x == 3) and "dummyskill" or table.concat(texts, ":")
  end,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player and player.phase == Player.Finish then
      return player:getMark("ls__hengzheng1") == 0 or player:getMark("ls__hengzheng2") == 0 or player:getMark("ls__hengzheng3") == 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local patterns = {"slash", "lvshi__snatch", "lvshi__fire_attack"}
    local n = 1
    if table.every(room.alive_players, function (p) return p.hp <= player.hp end) then
      n = 2
    end
    if player:getMark("ls__hengzheng3") == 0 and table.every(room:getOtherPlayers(player), function (p) return p.hp < player.hp end) then
      n = 3
    end
    if player:getMark("ls__hengzheng" .. n) > 0 then return end
    local targets = table.filter(room.alive_players, function (p) return player:inMyAttackRange(p) end)
    room:useVirtualCard(patterns[n], nil, player, targets, self.name)
    --[[if room:askForSkillInvoke(player, self.name, nil, "#lvshi__hengzheng-lose") then
      targets = table.filter(targets, function (p) return p:getHandcardNum() > player:getHandcardNum() end)
      room:addPlayerMark(player, "ls__hengzheng" .. n)
      if #targets > 0 then
        room:useVirtualCard(patterns[n], nil, player, targets, self.name)
      end
    end]]
    targets = table.filter(targets, function (p) return not p.dead end)
    local to = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, #targets, "#lvshi__hengzheng-lose", self.name, true)
    if #to > 0 then
      room:addPlayerMark(player, "ls__hengzheng" .. n)
      room:useVirtualCard(patterns[n], nil, player, table.map(to, Util.Id2PlayerMapper), self.name)
    end
    if player:getMark("hengzhengedit") > 0 then
      room:loseHp(player, 1, self.name)
    end
  end,

  refresh_events = {fk.PreCardUse},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and data.card.skillName == self.name
    and data.card.type == Card.TypeTrick
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addCardMark(data.card, "strategycourage")
  end,
}

local lvshi__weilin = fk.CreateTriggerSkill{
  name = "lvshi__weilin",
  frequency = Skill.Limited,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)--player.role_shown
    if player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 then
      return table.every(player.room.alive_players, function (p) return p:getHandcardNum() <= player:getHandcardNum() end)
      or #table.filter(player.room:getOtherPlayers(player), function(p) 
      return player.role == p.role or (table.contains({"lord", "loyalist"}, player.role) and table.contains({"lord", "loyalist"}, p.role)) end) == 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, 4)
    ls.recover(player, 3, self.name)
    local all_choices = {}
    for i = 1, 3, 1 do
      if player:getMark("ls__hengzheng"..i) > 0 then
        table.insert(all_choices, "ls__hengzheng"..i)
      end
    end
    if #all_choices > 0 then
      local choices = room:askForChoices(player, all_choices, 1, 2, self.name)
      for _, choice in ipairs(choices) do
        room:setPlayerMark(player, choice, 0)
      end
    end
    room:addPlayerMark(player, "hengzhengedit")
  end,
}

local lvshi__dichao = fk.CreateViewAsSkill{
  name = "lvshi__dichao$",
  pattern = "analeptic",
  prompt = "#lvshi__dichao",
  interaction = function (self)
    local room = Fk:currentRoom()
    local choices = {}
    for _, p in ipairs(room.alive_players) do
      local cards = table.filter(p:getCardIds("hej"), function (id)
        local card = Fk:getCardById(id)
        return card.suit == Card.Spade and (table.contains(p:getCardIds("ej"), id) or ls.isshown(card))
      end)
      table.insertTableIfNeed(choices, cards)
    end
    local all_choices = table.map(choices, function (id) return TT.getCardData(id, Fk:currentRoom()) end)
    return TT.CardNameBox { choices = choices, all_choices = all_choices, }
  end,
  card_filter = Util.FalseFunc,
  view_as = function (self, cards)
    if #cards == 0 then
      local card = Fk:cloneCard("lvshi__analeptic")
      card:addSubcard(self.interaction.data)
      card.skillName = self.name
      card:setMark(self.name, Fk:currentRoom():getCardOwner(self.interaction.data).id)
      return card
    end
  end,
  enabled_at_play = function (self, player)
    return player:usedSkillTimes(self.name, Player.HistoryTurn) < 1
  end,
  enabled_at_response = function (self, player, response)
    return player:usedSkillTimes(self.name, Player.HistoryTurn) < 1
  end,
  after_use = function (self, player, use)
    local room = player.room
    local target = room:getPlayerById(use.card:getMark(self.name))
    if target.kingdom ~= "qun" then
      room:changeMaxHp(player, -1)
    end
    use.card:setMark(self.name, 0)
  end,
}

dongzhuo:addSkill(lvshi__hengzheng)
dongzhuo:addSkill(lvshi__weilin)
dongzhuo:addSkill(lvshi__dichao)

Fk:loadTranslationTable{
  ["lvshi__dongzhuo"] = "董卓",
  ["#lvshi__dongzhuo"] = "取国填壑",
  ["designer:lvshi__dongzhuo"] = "懂太师",
  ["lvshi__hengzheng"] = "横征",
  [":lvshi__hengzheng"] = "结束阶段，若你的体力值不为/为/为唯一最大，你视为使用目标为攻击范围内所有角色的【杀】/【顺手牵羊】/【火攻】（均视为勇策略），然后你可删去对应项，再视为对其中任意名角色使用之。",
  [":ls__hengzheng_inner"] = "结束阶段，{1}{2}{3}{4}{5}{6}{7}{8}{9}",
  [":dummyskill"] = "无效果。",
  ["ls__hengzheng_color"] = "<font color='gray'>",
  ["ls__hengzheng1"] = "【杀】",
  ["ls__hengzheng2"] = "勇策略【顺手牵羊】",
  ["ls__hengzheng3"] = "勇策略【火攻】",
  ["#lvshi__hengzheng-lose"] = "你可以删去此项，视为对其中任意名角色使用之",
  ["lvshi__hengzheng1"] = "若你的体力值不为最大，你视为使用目标为攻击范围内所有角色的【杀】；",
  ["lvshi__hengzheng2"] = "若你的体力值为最大，你视为使用目标为攻击范围内所有角色的勇策略【顺手牵羊】；",
  ["lvshi__hengzheng3"] = "若你的体力值为唯一最大，你视为使用目标为攻击范围内所有角色的勇策略【火攻】；",
  ["hengzhengedit"] = "<font color='#E8251E'>然后你失去1点体力</font>",
  ["hengzheng_tail"] = "且你可删去对应项，再视为对其中任意名角色使用之。",
  ["lvshi__weilin"] = "威临",
  [":lvshi__weilin"] = "限定技，一名角色的回合结束后，若你的手牌数为场上最大或没有存活的其他己方角色，你可增加4点体力上限，回复3点体力，复原“横征”的两项， “横征”描述增加“你失去1点体力”",

  ["lvshi__dichao"] = "涤朝",
  ["#lvshi__dichao"] = "你可弃置场上或一名角色明置的一张黑桃牌，视为使用【酒】",
  [":lvshi__dichao"] = "主公技，回合技，你可将一名角色场上或明置的一张黑桃牌当【酒】使用，若其不为群势力角色，你减1点体力上限。",

  ["$lvshi__hengzheng1"] = "尔欲行大事？问过吾掌中兵刃否？",
  ["$lvshi__hengzheng2"] = "西凉铁骑曳城，天下高楼可摧。",
  ["$lvshi__weilin1"] = "今吾入京城，欲寻人而食。",
  ["$lvshi__weilin2"] = "天下事在我，我今为之，谁敢不从？",
  ["$lvshi__dichao1"] = "满朝诸公，视吾剑不利否？",
  ["$lvshi__dichao2"] = "顺我者生，逆我者十死无生。",
  ["~lvshi__dongzhuo"] = "貂蝉之事，再勿多言，言则必斩。",
}

local lvbu = General(extension, "lvshi__lvbu", "qun", 5)
lvbu.strategy = "courage"

local lvshi__wushuang = fk.CreateTriggerSkill{
  name = "lvshi__wushuang",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.CardUseFinished, fk.BeforeCardsMove},
  can_trigger = function(self, event, target, player, data)
    if event == fk.CardUseFinished then
      return target == player and player:hasSkill(self) and data.tos and data.card.trueName == "slash"
      and data.card.skillName ~= self.name
    elseif player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.from and move.from == player.id and move.moveReason == fk.ReasonResonpse then
          local resp = player.room.logic:getCurrentEvent():findParent(GameEvent.RespondCard, true).data[1]
          if not resp.card:isVirtual() and resp.card.trueName == "slash" then
            for _,info in ipairs(move.moveInfo) do
              if info.fromArea == Card.PlayerHand and Fk:getCardById(info.cardId).trueName == "slash"
              and not table.contains(DIY.GetShownCards(player), info.cardId) then
                return true
              end
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.CardUseFinished then
      local targets = U.getActualUseTargets(player.room, data, event)
      player.room:useVirtualCard(data.card.name, nil, player, table.map(targets, Util.Id2PlayerMapper), self.name, true)
    else
      for _, move in ipairs(data) do
        for _, info in ipairs(move.moveInfo) do
          DIY.ShowCards(player,{info.cardId})
        end
        move.moveInfo = {}
      end
    end
  end,
}

local wuqian_record = fk.CreateTriggerSkill{
  name = "#lvshi__wuqian_record",
  refresh_events = {fk.Damage},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "wuqian-turn")
    player:filterHandcards()
  end,
}

local wuqian_targetmod = fk.CreateTargetModSkill{
  name = "#lvshi__wuqian_targetmod",
  extra_target_func = function(self, player, skill, card)
    if player:hasSkill("lvshi__wuqian") and card and card.trueName == "duel" then
      return 2
    end
  end,
}

local lvshi__wuqian = fk.CreateFilterSkill{
  name = "lvshi__wuqian",
  frequency = Skill.Compulsory,
  card_filter = function(self, to_select, player)
    return player:hasSkill(self.name) and to_select:isCommonTrick() and to_select.color == Card.Black
    and player.phase ~= Player.NotActive and player:getMark("wuqian-turn") == 0
  end,
  view_as = function(self, to_select)
    return Fk:cloneCard("lvshi__duel", to_select.suit, to_select.number)
  end,
}

lvshi__wuqian:addRelatedSkill(wuqian_record)
lvshi__wuqian:addRelatedSkill(wuqian_targetmod)
lvbu:addSkill(lvshi__wushuang)
lvbu:addSkill(lvshi__wuqian)

Fk:loadTranslationTable{
  ["lvshi__lvbu"] = "吕布",
  ["#lvshi__lvbu"] = "撼坤震岳",
  ["designer:lvshi__lvbu"] = "氯",
  ["#lvshi__wushuang_delay"] = "无双",
  ["lvshi__wushuang"] = "无双",
  [":lvshi__wushuang"] = "锁定技，你不因“无双”使用【杀】后，视为对目标角色再使用之；你打出非明置【杀】时，改为明置之。",
  ["lvshi__wuqian"] = "无前",
  [":lvshi__wuqian"] = "锁定技，你使用【决斗】的目标上限数+2；你的回合内，若你未于此回合造成过伤害，则你的黑色锦囊牌视为【决斗】。",
  ["$lvshi__wushuang1"] = "修罗降世，神鬼辟易！",
  ["$lvshi__wushuang2"] = "殃云天降，修罗挥兵！",
  ["$lvshi__wuqian1"] = "且断轮回化魔躯，不擒汝首誓不还！",
  ["$lvshi__wuqian2"] = "神魔天征，挡我者死！",
  ["~lvshi__lvbu"] = "人，无信不利，吾，悔之晚矣。",
}


local jiaxu = General(extension, "lvshi__jiaxu", "qun", 3)
jiaxu.strategy = "scheme"

local ls__qianlve = fk.CreateTriggerSkill{
  name = "lvshi__qianlve",
  anim_type = "special",
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.card.trueName == "peach" and not ls.isFriend(player, target)
    and player:usedSkillTimes(self.name, Player.HistoryRound) == 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#ls__qianlve-invoke::"..target.id..":"..data.card:toLogString())
  end,
  on_use = function(self, event, target, player, data)
    table.insertIfNeed(data.nullifiedTargets, target.id)
    if data.from ~= target.id then
      player:setSkillUseHistory(self.name, 0, Player.HistoryRound)
    end
  end,
}

local ls__weimu = fk.CreateTriggerSkill{
  name = "lvshi__weimu",
  anim_type = "defensive",
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.card.type == Card.TypeTrick and data.card.color == Card.Black
    and player:usedSkillTimes(self.name, Player.HistoryRound) == 0 and (ls.isFriend(player, target) or player == target)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#ls__weimu-invoke::"..target.id..":"..data.card:toLogString())
  end,
  on_use = function(self, event, target, player, data)
    if data.card.sub_type == Card.SubtypeDelayedTrick then
      AimGroup:cancelTarget(data, target.id)
    else
      table.insertIfNeed(data.nullifiedTargets, target.id)
    end
    if target == player then
      player:setSkillUseHistory(self.name, 0, Player.HistoryRound)
    end
  end,
}

local fengbo = fk.CreateTriggerSkill{
  name = "lvshi__fengbo",
  anim_type = "offensive",
  frequency = Skill.Limited,
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {"lvshi__fengbo_throw:"..target.id, "lvshi__fengbo_recover:"..target.id}
    local choice = room:askForChoice(player, choices, self.name)
    if choice == choices[1] then
      room:askForDiscard(target, 4, 4, false, self.name, false)
      room:handleAddLoseSkills(player, "lvshi__luanwu")
    else
      room:recover{who = target, num = 2, recoverBy = player, skillName = self.name}
      room:handleAddLoseSkills(player, "lvshi__jianshu")
    end
  end,
}

local jianshu = fk.CreateActiveSkill{
  name = "lvshi__jianshu",
  anim_type = "control",
  prompt = "#lvshi__jianshu-prompt",
  card_num = 1,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isKongcheng()
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).color == Card.Black
  end,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:obtainCard(target.id, Fk:getCardById(effect.cards[1]), false, fk.ReasonGive)
    local targets = {}
    for _, p in ipairs(room:getOtherPlayers(target)) do
      if not p:isKongcheng() and p ~= player then
        table.insert(targets, p.id)
      end
    end
    if #targets == 0 then return end
    local to = room:askForChoosePlayers(player, targets, 1, 1, "#lvshi__jianshu-choose::"..target.id, self.name, false)
    if #to == 0 then
      to = room:getPlayerById(table.random(targets))
    else
      to = room:getPlayerById(to[1])
    end
    local pindian = target:pindian({to}, self.name)
    if pindian.results[to.id].winner then
      local winner, loser
      if pindian.results[to.id].winner == target then
        winner = target
        loser = to
      else
        winner = to
        loser = target
      end
      if not winner:isKongcheng() and not winner.dead then
        local card = room:askForCard(winner, 1, 1, false, self.name, false, ".", "#lvshi__jianshu-give:"..player.id)
        room:obtainCard(player.id, card[1], false, fk.ReasonGive)
      end
      if not loser.dead then
        room:loseHp(loser, 1, self.name)
      end
    else
      if not target.dead then
        room:loseHp(target, 1, self.name)
      end
      if not to.dead then
        room:loseHp(to, 1, self.name)
      end
    end
  end
}

local luanwu = fk.CreateViewAsSkill {
  name = "lvshi__luanwu",
  pattern = "wenhe_chaos",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).color == Card.Black
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return nil end
    local card = Fk:cloneCard("wenhe_chaos")
    card.skillName = self.name
    card:addSubcards(cards)
    return card
  end,
  enabled_at_play = function(self, player)
    return player:getMark("@@lvshi_readying:::"..self.name) == 0
  end,
  before_use = function(self, player, use)
    player:drawCards(1, self.name)
  end
}
luanwu.XushiSkill = true

--[[
local fengbo = fk.CreateTriggerSkill{
  name = "lvshi__fengbo",
  anim_type = "offensive",
  frequency = Skill.Limited,
  events = {fk.RoundStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askForChoice(player, {"lvshi__fengbo_damaged", "lvshi__fengbo_damage"}, self.name)
    room:addPlayerMark(player, choice.."-round")
    local targets = room:getAlivePlayers()
    room:doIndicate(player.id, table.map(targets, Util.IdMapper))
    local choices = {"lvshi__fengbo_poison", "lvshi__fengbo_turnover", "lvshi__fengbo_draw2"}
    local result = ls.AskForChoicesConcurrent(targets, choices, 2, self.name, "#lvshi__fengbo-choice")
    for _, p in ipairs(targets) do
      local ret = result[p.id]
      if not p.dead then
        if table.contains(ret, choices[1]) then
          room:setPlayerMark(p, "@@lvshi__fengbo_zhendu-round", 1)
          room:handleAddLoseSkills(p, "lvshi__zhendu")
          room.logic:getCurrentEvent():findParent(GameEvent.Round):addCleaner(function()
            room:handleAddLoseSkills(p, "-lvshi__zhendu")
          end)
        end
      end
      if not p.dead and table.contains(ret, choices[2]) then
        p:turnOver()
      end
      if not p.dead and table.contains(ret, choices[3]) then
        p:drawCards(2, self.name)
      end
    end
  end,

  refresh_events = {fk.DamageCaused, fk.DamageInflicted},
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player then
      if event == fk.DamageCaused then
        return player:getMark("lvshi__fengbo_damage-round") > 0 and (not player.room.current or player.room.current ~= player)
      else
        return player:getMark("lvshi__fengbo_damaged-round") > 0 and player.room.current and player.room.current == player
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    if event == fk.DamageCaused then
      data.damage = data.damage + 1
    else
      data.damage = data.damage - 1
    end
  end,
}
]]

jiaxu:addSkill(ls__qianlve)
jiaxu:addSkill(ls__weimu)
jiaxu:addSkill(fengbo)
jiaxu:addRelatedSkill(luanwu)
jiaxu:addRelatedSkill(jianshu)

local lvshi__zhendu = fk.CreateTriggerSkill{
  name = "lvshi__zhendu",
  mute = true,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.phase == Player.Play and not player:isKongcheng() and not target.dead
  end,
  on_cost = function(self, event, target, player, data)
    local prompt = (target == player) and "#lvshi__zhendu-self" or "#lvshi__zhendu-invoke::"..target.id
    local card = player.room:askForDiscard(player, 1, 1, false, self.name, true, ".", prompt, true)
    if #card > 0 then
      player.room:doIndicate(player.id, {target.id})
      self.cost_data = {tos = {target.id}, cards = card}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name, player:isMale() and 1 or 2)
    room:notifySkillInvoked(player, self.name, "offensive", {target.id})
    room:throwCard(self.cost_data.cards, self.name, player, player)
    if not target.dead then
      room:useVirtualCard("analeptic", nil, target, target, self.name, true)
    end
    if player ~= target and not target.dead then
      room:damage{
        from = player,
        to = target,
        damage = 1,
        skillName = self.name,
      }
    end
  end,
  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player, "@@lvshi__fengbo_zhendu-round", 0)
  end,
}

--jiaxu:addRelatedSkill(lvshi__zhendu)

Fk:loadTranslationTable{
  ["lvshi__jiaxu"] = "贾诩",
  ["#lvshi__jiaxu"] = "宫鸣醒世",
  ["designer:lvshi__jiaxu"] = "圣&氯",

  ["lvshi__qianlve"] = "箝略",
  [":lvshi__qianlve"] = "轮次技，非己方角色成为【桃】的目标后，你可令之无效，若使用者不为其，重置此技能。",
  ["#ls__qianlve-invoke"] = "箝略：你可令%arg对%dest无效",
  ["lvshi__weimu"] = "帷幕",
  [":lvshi__weimu"] = "轮次技，你或己方角色成为黑色锦囊牌的目标后，你可令之无效，若目标为你，重置此技能。",
  ["#ls__weimu-invoke"] = "帷幕：你可令%arg对%dest无效",

  ["lvshi__fengbo"] = "择势",
  ["lvshi__fengbo_throw"] = "令%src弃置四张手牌",
  ["lvshi__fengbo_recover"] = "令%src回复2点体力",
  [":lvshi__fengbo"] = "限定技，当一名角色进入濒死状态时。你可选择一项：令其弃置四张手牌，然后你获得“乱武”；或令其回复2点体力，然后你获得“间书”。",
  ["lvshi__jianshu"] = "间书",   
  [":lvshi__jianshu"] = "阶段技，你可将一张黑色牌交给一名其他角色，然后选择另一名其他角色，令这两名角色拼点：赢的角色交给你一张手牌，没赢的角色失去1点体力。",  
  ["#lvshi__jianshu-prompt"] = "间书：你可将一张黑色牌交给一名其他角色",  
  ["#lvshi__jianshu-choose"] = "间书：请选择另一名其他角色，令其和 %dest 拼点", 
  ["#lvshi__jianshu-give"] = "间书：请交给%src一张手牌",
  ["lvshi__luanwu"] = "乱武",
  [":lvshi__luanwu"] = "<a href='lvshi_xushi_skill'>蓄势技</a>，出牌阶段，你可将一张黑色牌当<a href=':wenhe_chaos'>【文和乱武】</a>使用并摸一张牌。", 
  ["@@lvshi_readying:::lvshi__luanwu"] = "乱武行置",  
  ["#luanwu-use"] = "请对距离最近的角色视为【杀】，否则你失去1点体力",
  --[[[":lvshi__fengbo"] = "限定技，轮次开始时，你可暗中选择此轮你回合内受到的伤害-1或回合外造成的伤害+1，然后所有角色同时选择两项：1.于本轮获得“鸩毒”；2.翻面；3.摸两张牌。",
  ["lvshi__fengbo_damaged"] = "受到的伤害-1",
  ["lvshi__fengbo_damage"] = "造成的伤害+1",
  ["lvshi__fengbo_poison"] = "于本轮获得“鸩毒”",
  ["lvshi__fengbo_turnover"] = "翻面",
  ["lvshi__fengbo_draw2"] = "摸两张牌",
  ["#lvshi__fengbo-choice"] = "纷殕：请选择执行2项效果",
  ["@@lvshi__fengbo_zhendu-round"] = "鸩毒",]]

  ["lvshi__zhendu"] = "鸩毒",
  [":lvshi__zhendu"] = "一名角色的出牌阶段开始时，你可弃置一张手牌。若如此做，该角色视为使用一张【酒】，然后若该角色不为你，你对其造成1点伤害。",
  ["#lvshi__zhendu-invoke"] = "鸩毒：你可以弃置一张手牌视为 %dest 使用一张【酒】，然后你对其造成1点伤害",
  ["#lvshi__zhendu-self"] = "鸩毒：你可以弃置一张手牌视为使用一张【酒】",

  ["$lvshi__qianlve1"] = "吾之所好，杀人诛心。",
  ["$lvshi__qianlve2"] = "汝可遣使相问，四下可有援军？",
  ["$lvshi__weimu1"] = "施经布略由我，剩下的，任由将军！",  
  ["$lvshi__weimu2"] = "兵以诈立，不如，任其来攻！",  
  ["$lvshi__fengbo1"] = "孤立川上，观逝者如东去之流水。",
  ["$lvshi__fengbo2"] = "九州如画，怎可空老人间？",
  ["$lvshi__jianshu1"] = "令其相疑，则一鼓可破也。",
  ["$lvshi__jianshu2"] = "貌合神离，正合用反间之计。",
  ["$lvshi__luanwu1"] = "哼哼哼，坐山观虎斗！",
  ["$lvshi__luanwu2"] = "哭喊吧，哀求吧，挣扎吧，然后，死吧！",
  
  ["~lvshi__jiaxu"] = "算无遗策，然终有疏漏。",

}

local jushou = General(extension, "lvshi__jushou", "qun", 3)
jushou.strategy = "scheme"

local lvshi__jianying = fk.CreateTriggerSkill{
  name = "lvshi__jianying",
  anim_type = "control",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player and #player:getTableMark("@lvshi__jianying-turn") > 0 and data.card.number > 0 then
      return data.card.number < player:getTableMark("@lvshi__jianying-turn")[1] or data.card.number > player:getTableMark("@lvshi__jianying-turn")[2]
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    if data.card.number < player:getTableMark("@lvshi__jianying-turn")[1] then
      player.room:setPlayerMark(player, "@lvshi__jianying-turn", {data.card.number, player:getTableMark("@lvshi__jianying-turn")[2]})
    end
    if data.card.number > player:getTableMark("@lvshi__jianying-turn")[2] then
      player.room:setPlayerMark(player, "@lvshi__jianying-turn", {player:getTableMark("@lvshi__jianying-turn")[1], data.card.number})
    end
    player:drawCards(1, self.name)
  end,

  refresh_events = {fk.AfterCardUseDeclared},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.number > 0 and #player:getTableMark("@lvshi__jianying-turn") == 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@lvshi__jianying-turn", {data.card.number, data.card.number})
  end,
}

local lvshi__shibei = fk.CreateViewAsSkill {
  name = "lvshi__shibei",
  pattern = "jink,nullification",
  card_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return nil end
    local card = Fk:cloneCard("lvshi__jink")
    if Fk.currentResponsePattern == "nullification" then
      card = Fk:cloneCard("lvshi__nullification")
    end
    card.skillName = self.name
    card:addSubcards(cards)
    return card
  end,
  enabled_at_play = Util.FalseFunc,
  enabled_at_response = function(self, player, response)
    if response then return false end
    return player:getMark("@@lvshi_readying:::"..self.name) == 0
  end
}

local shibei_reset = fk.CreateTriggerSkill{
  name = "#lvshi__shibei_reset",
  refresh_events = {fk.AfterCardUseDeclared, fk.Damaged},
  can_refresh = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player:getMark("@@lvshi_readying:::lvshi__shibei") > 0 then
      if event == fk.AfterCardUseDeclared then
        return (data.card.trueName == "jink" or data.card.trueName == "nullification") and data.card.skillName ~= "lvshi__shibei"
      else
        return true
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@lvshi_readying:::lvshi__shibei", 0)
  end,
}


lvshi__shibei.XushiSkill = true
lvshi__shibei:addRelatedSkill(shibei_reset)
jushou:addSkill(lvshi__jianying)
jushou:addSkill(lvshi__shibei)

Fk:loadTranslationTable{
  ["lvshi__jushou"] = "沮授",
  ["#lvshi__jushou"] = "谋堪良平",
  ["designer:lvshi__jushou"] = "氯",
  ["lvshi__jianying"] = "渐营",
  ["@lvshi__jianying-turn"] = "渐营",
  [":lvshi__jianying"] = "当你使用牌时，若此牌点数大于或小于你于此回合使用过的所有牌，则你摸一张牌。",
  ["lvshi__shibei"] = "矢北",
  [":lvshi__shibei"] = "<a href='lvshi_xushi_skill'>蓄势技</a>，你可将一张牌当【闪】或【无懈可击】使用；当你不以此法使用【闪】或【无懈可击】或受到伤害后，你重置此技能。",
  ["@@lvshi_readying:::lvshi__shibei"] = "矢北行置",

  ["$lvshi__jianying1"] = "缓耗蚕食，乃万安之法。",
  ["$lvshi__jianying2"] = "图南宜缓，需从长计议。",
  ["$lvshi__shibei1"] = "唯寄归心，随雁北还。",
  ["$lvshi__shibei2"] = "我如逆磁，矢志司北。",
  ["~lvshi__jushou"] = "悠悠我心悲，何日归河北。",
}

local gongsunzan = General(extension, "lvshi__gongsunzan", "qun", 4)
gongsunzan.strategy = "courage"

local ls__zhuhu = fk.CreateTriggerSkill{
  name = "lvshi__zhuhu",
  anim_type = "offensive",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.card.trueName == "slash" and #TargetGroup:getRealTargets(data.tos) > 0
    and player:usedSkillTimes(self.name) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = {}
    for _, id in ipairs(TargetGroup:getRealTargets(data.tos)) do
      local p = room:getPlayerById(id)
      if not player:isProhibited(p, Fk:cloneCard("lvshi__lure_tiger")) and not p.dead then
        table.insertIfNeed(targets, p.id)
      end
    end
    if #targets == 0 then return false end
    local to = player.room:askForChoosePlayers(player, targets, 1, 1, "#lvshi__zhuhu-target", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(1, self.name)
    room:useVirtualCard("lvshi__lure_tiger", nil, player, room:getPlayerById(self.cost_data), self.name, true)
    room:addPlayerMark(player, "@lvshi__zhuhu-turn")
    if not data.damageDealt then
      player:setSkillUseHistory(self.name, 0, Player.HistoryTurn)
    end
  end,

  refresh_events = {fk.DamageCaused},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@lvshi__zhuhu-turn") > 0 and data.card and data.card.trueName == "slash"
  end,
  on_refresh = function(self, event, target, player, data)
    data.damage = data.damage + player:getMark("@lvshi__zhuhu-turn")
  end,
}

local zhuhu_targetmod = fk.CreateTargetModSkill{
  name = "#lvshi__zhuhu_targetmod",
  residue_func = function(self, player, skill, scope, card)
    if skill.trueName == "slash_skill" and card and player:getMark("@lvshi__zhuhu-turn") > 0 and scope == Player.HistoryPhase then
      return player:getMark("@lvshi__zhuhu-turn")
    end
  end,
  distance_limit_func =  function(self, player, skill)
    if player:hasSkill(self.name) and skill.trueName == "slash_skill" and player:getMark("@lvshi__zhuhu-turn") > 0 then
      return 999
    end
  end,
}

local ls__zhuhuu = fk.CreateTriggerSkill{
  name = "lvshi__zhuhuu",
  anim_type = "defensive",
  events = {fk.TargetConfirmed, fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if event == fk.TargetConfirmed then
      return target == player and player:hasSkill(self.name) and data.firstTarget and data.card.trueName == "slash" and player:getHandcardNum() < 4
      and not string.find(data.card.name, "fire__slash")
    else
      return (not target.dead) and data.card.trueName == "slash" and player:hasSkill(self.name) and player:getHandcardNum() > player.hp and data.extra_data and data.extra_data.ls__zhuhuu
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TargetConfirmed then
      return player.room:askForSkillInvoke(player, self.name)
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetConfirmed then
      player:drawCards(4 - player:getHandcardNum(), self.name)
      data.extra_data = data.extra_data or {}
      data.extra_data.ls__zhuhuu = player.id
    else
      local id = data.extra_data.ls__zhuhuu
      room:useVirtualCard("lvshi__lure_tiger", nil, target, room:getPlayerById(id), self.name, true)       
    end
  end,
}

ls__zhuhu:addRelatedSkill(zhuhu_targetmod)
gongsunzan:addSkill(ls__zhuhu)
gongsunzan:addSkill(ls__zhuhuu)

Fk:loadTranslationTable{
  ["lvshi__gongsunzan"] = "公孙瓒",
  ["lvshi__zhuhu"] = "逐胡",
  ["@lvshi__zhuhu-turn"] = "逐胡",
  [":lvshi__zhuhu"] = "回合技，当你使用【杀】结算后，你可视为对一名目标角色使用【调虎离山】并摸一张牌，然后你于此回合使用【杀】次数上限和造成的伤害+1，若此【杀】未造成伤害，重置此技能。",
  ["#lvshi__zhuhu-target"] = "逐胡：你可视为对一名目标角色使用【调虎离山】",
  ["lvshi__zhuhuu"] = "筑縠",
  [":lvshi__zhuhuu"] = "当你成为非火【杀】的目标后，你可将手牌补至四张，然后此【杀】结算后，若你的手牌数大于体力值，此【杀】的使用者视为对你使用【调虎离山】。",

  ["$lvshi__zhuhu1"] = "驰骋疆场，张弓搭箭，以射敌酋！",
  ["$lvshi__zhuhu2"] = "纵横草原，拔剑擎枪，直取寇首！",
  ["$lvshi__zhuhuu1"] = "列之所至，白马为证！",
  ["$lvshi__zhuhuu2"] = "避敌锋芒，以守为攻！",
  ["~lvshi__gongsunzan"] = "野望宏图，终成一炬。",
}

return extension